Skip to content
Browse files

TW-21103

  • Loading branch information...
1 parent ca10107 commit 8c044d08afd3639839036b501e0501d1a853a92f @jonnyzzz jonnyzzz committed May 10, 2012
View
23 nuget-server/src/jetbrains/buildServer/nuget/server/trigger/impl/TriggerRequestFactory.java
@@ -16,9 +16,12 @@
package jetbrains.buildServer.nuget.server.trigger.impl;
+import jetbrains.buildServer.RootUrlHolder;
+import jetbrains.buildServer.agent.AgentRuntimeProperties;
import jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor;
import jetbrains.buildServer.buildTriggers.BuildTriggerException;
import jetbrains.buildServer.nuget.server.toolRegistry.NuGetToolManager;
+import jetbrains.buildServer.parameters.ReferencesResolverUtil;
import jetbrains.buildServer.util.StringUtil;
import org.jetbrains.annotations.NotNull;
@@ -34,21 +37,24 @@
private final CheckRequestModeFactory myModeFactory;
private final NuGetToolManager myManager;
private final PackageCheckRequestFactory myRequestFactory;
+ private final RootUrlHolder myHolder;
public TriggerRequestFactory(@NotNull final CheckRequestModeFactory modeFactory,
@NotNull final NuGetToolManager manager,
- @NotNull final PackageCheckRequestFactory requestFactory) {
+ @NotNull final PackageCheckRequestFactory requestFactory,
+ @NotNull final RootUrlHolder holder) {
myModeFactory = modeFactory;
myManager = manager;
myRequestFactory = requestFactory;
+ myHolder = holder;
}
@NotNull
public PackageCheckRequest createRequest(@NotNull BuildTriggerDescriptor descriptor) throws BuildTriggerException {
- final String path = myManager.getNuGetPath(descriptor.getProperties().get(NUGET_EXE));
- final String pkgId = descriptor.getProperties().get(PACKAGE);
- final String version = descriptor.getProperties().get(VERSION);
- final String source = descriptor.getProperties().get(SOURCE);
+ String path = myManager.getNuGetPath(descriptor.getProperties().get(NUGET_EXE));
+ String pkgId = descriptor.getProperties().get(PACKAGE);
+ String version = descriptor.getProperties().get(VERSION);
+ String source = descriptor.getProperties().get(SOURCE);
if (StringUtil.isEmptyOrSpaces(path)) {
throw new BuildTriggerException("Path to NuGet.exe must be specified");
@@ -63,6 +69,13 @@ public PackageCheckRequest createRequest(@NotNull BuildTriggerDescriptor descrip
throw new BuildTriggerException("Failed to find NuGet.exe at: " + nugetPath);
}
+ if (source != null && ReferencesResolverUtil.mayContainReference(source)) {
+ final String rootUrlPattern = "%" + AgentRuntimeProperties.TEAMCITY_SERVER_URL + "%";
+ final String rootUrlValue = myHolder.getRootUrl();
+
+ source = source.replace(rootUrlPattern, rootUrlValue);
+ }
+
return myRequestFactory.createRequest(
myModeFactory.createNuGetChecker(nugetPath),
source,
View
27 nuget-tests/src/jetbrains/buildServer/nuget/tests/server/NamedPackagesUpdateCheckerTest.java
@@ -17,6 +17,8 @@
package jetbrains.buildServer.nuget.tests.server;
import jetbrains.buildServer.BaseTestCase;
+import jetbrains.buildServer.RootUrlHolder;
+import jetbrains.buildServer.agent.AgentRuntimeProperties;
import jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor;
import jetbrains.buildServer.buildTriggers.BuildTriggerException;
import jetbrains.buildServer.nuget.server.exec.SourcePackageInfo;
@@ -43,6 +45,7 @@
import java.io.File;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;
@@ -59,6 +62,8 @@
private PackageChangesManager chk;
private Map<String, String> params;
private File nugetFakePath;
+ private RootUrlHolder myRootUrlHolder;
+
private boolean myIsWindows;
@@ -74,10 +79,11 @@ protected void setUp() throws Exception {
params = new TreeMap<String, String>();
manager = m.mock(NuGetToolManager.class);
chk = m.mock(PackageChangesManager.class);
+ myRootUrlHolder = m.mock(RootUrlHolder.class);
final SystemInfo si = m.mock(SystemInfo.class);
- checker = new NamedPackagesUpdateChecker(chk, new TriggerRequestFactory(new CheckRequestModeFactory(si), manager, new PackageCheckRequestFactory(new PackageCheckerSettingsImpl())), new PackagesHashCalculator());
+ checker = new NamedPackagesUpdateChecker(chk, new TriggerRequestFactory(new CheckRequestModeFactory(si), manager, new PackageCheckRequestFactory(new PackageCheckerSettingsImpl()), myRootUrlHolder), new PackagesHashCalculator());
nugetFakePath = Paths.getNuGetRunnerPath();
final String path = nugetFakePath.getPath();
@@ -97,6 +103,25 @@ public Object invoke(Invocation invocation) throws Throwable {
}
@Test
+ public void test_resolves_own_feed_url() {
+ params.put(TriggerConstants.SOURCE, "%"+ AgentRuntimeProperties.TEAMCITY_SERVER_URL+"%/a/b/c");
+
+ m.checking(new Expectations(){{
+ allowing(myRootUrlHolder).getRootUrl(); will(returnValue("http://some-teamcity-with-nuget.org/jonnyzzz"));
+
+ oneOf(chk).checkPackage(with(req(nugetFakePath, "http://some-teamcity-with-nuget.org/jonnyzzz/a/b/c", "NUnit", null)));
+ will(returnValue(CheckResult.succeeded(Collections.<SourcePackageInfo>emptyList())));
+
+ oneOf(store).getValue("hash"); will(returnValue(null));
+ oneOf(store).putValue(with(equal("hash")), with(any(String.class)));
+ oneOf(store).flush();
+ }});
+ Assert.assertNull(checker.checkChanges(desr, store));
+
+ m.assertIsSatisfied();
+ }
+
+ @Test
public void test_check_first_time_should_not_trigger() {
m.checking(new Expectations(){{
oneOf(chk).checkPackage(with(req(nugetFakePath, null, "NUnit", null)));

0 comments on commit 8c044d0

Please sign in to comment.
Something went wrong with that request. Please try again.