From fd232f43bc08ff0d91b257d2aca5ebc3a6aef1e4 Mon Sep 17 00:00:00 2001 From: "Eugene.Petrenko" Date: Tue, 23 Aug 2011 18:41:54 +0200 Subject: [PATCH] code reuse, no need to register runners explicitly as agent searches for runner implementations --- .../build-agent-plugin-nuget-install.xml | 1 - .../build-agent-plugin-nuget-pack.xml | 1 - .../build-agent-plugin-nuget-publish.xml | 1 - .../src/META-INF/build-agent-plugin-nuget.xml | 1 - .../nuget/agent/runner/NuGetRunnerBase.java | 64 +++++++++++++++++++ .../install/PackagesInstallerRunner.java | 45 +++---------- .../PackagesInstallerRunnerRegistrar.java | 31 --------- .../nuget/agent/runner/pack/PackRunner.java | 37 ++--------- .../runner/pack/PackRunnerRegistrar.java | 31 --------- .../runner/publish/PackagesPublishRunner.java | 36 ++--------- .../PackagesPublishRunnerRegistrar.java | 31 --------- 11 files changed, 86 insertions(+), 193 deletions(-) create mode 100644 nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/NuGetRunnerBase.java delete mode 100644 nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/install/PackagesInstallerRunnerRegistrar.java delete mode 100644 nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/pack/PackRunnerRegistrar.java delete mode 100644 nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/publish/PackagesPublishRunnerRegistrar.java diff --git a/nuget-agent/src/META-INF/build-agent-plugin-nuget-install.xml b/nuget-agent/src/META-INF/build-agent-plugin-nuget-install.xml index dca988b..11074a4 100644 --- a/nuget-agent/src/META-INF/build-agent-plugin-nuget-install.xml +++ b/nuget-agent/src/META-INF/build-agent-plugin-nuget-install.xml @@ -5,7 +5,6 @@ http://www.springframework.org/schema/beans/spring-beans-2.5.xsd" default-autowire="constructor"> - diff --git a/nuget-agent/src/META-INF/build-agent-plugin-nuget-pack.xml b/nuget-agent/src/META-INF/build-agent-plugin-nuget-pack.xml index 96e31b5..1a1f790 100644 --- a/nuget-agent/src/META-INF/build-agent-plugin-nuget-pack.xml +++ b/nuget-agent/src/META-INF/build-agent-plugin-nuget-pack.xml @@ -6,6 +6,5 @@ default-autowire="constructor"> - \ No newline at end of file diff --git a/nuget-agent/src/META-INF/build-agent-plugin-nuget-publish.xml b/nuget-agent/src/META-INF/build-agent-plugin-nuget-publish.xml index 899cd07..ce06a72 100644 --- a/nuget-agent/src/META-INF/build-agent-plugin-nuget-publish.xml +++ b/nuget-agent/src/META-INF/build-agent-plugin-nuget-publish.xml @@ -6,6 +6,5 @@ default-autowire="constructor"> - \ No newline at end of file diff --git a/nuget-agent/src/META-INF/build-agent-plugin-nuget.xml b/nuget-agent/src/META-INF/build-agent-plugin-nuget.xml index 3b03c16..7ef0cff 100644 --- a/nuget-agent/src/META-INF/build-agent-plugin-nuget.xml +++ b/nuget-agent/src/META-INF/build-agent-plugin-nuget.xml @@ -22,5 +22,4 @@ - \ No newline at end of file diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/NuGetRunnerBase.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/NuGetRunnerBase.java new file mode 100644 index 0000000..850743b --- /dev/null +++ b/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/NuGetRunnerBase.java @@ -0,0 +1,64 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package jetbrains.buildServer.nuget.agent.runner; + +import com.intellij.openapi.diagnostic.Logger; +import jetbrains.buildServer.agent.AgentBuildRunner; +import jetbrains.buildServer.agent.AgentBuildRunnerInfo; +import jetbrains.buildServer.agent.BuildAgentConfiguration; +import jetbrains.buildServer.nuget.agent.commands.NuGetActionFactory; +import jetbrains.buildServer.nuget.agent.parameters.PackagesParametersFactory; +import jetbrains.buildServer.nuget.common.DotNetConstants; +import org.jetbrains.annotations.NotNull; + +/** + * @author Eugene Petrenko (eugene.petrenko@gmail.com) + * Date: 23.08.11 18:32 + */ +public abstract class NuGetRunnerBase implements AgentBuildRunner, AgentBuildRunnerInfo { + protected final Logger LOG = Logger.getInstance(getClass().getName()); + + protected final NuGetActionFactory myActionFactory; + protected final PackagesParametersFactory myParametersFactory; + + public NuGetRunnerBase(NuGetActionFactory actionFactory, PackagesParametersFactory parametersFactory) { + myActionFactory = actionFactory; + myParametersFactory = parametersFactory; + } + + @NotNull + public AgentBuildRunnerInfo getRunnerInfo() { + return this; + } + + @NotNull + public abstract String getType(); + + public boolean canRun(@NotNull BuildAgentConfiguration agentConfiguration) { + if (!agentConfiguration.getSystemInfo().isWindows()) { + LOG.warn("NuGet packages installer available only under windows"); + return false; + } + + if (!agentConfiguration.getConfigurationParameters().containsKey(DotNetConstants.DOT_NET_FRAMEWORK_4_x86)) { + LOG.warn("NuGet requires .NET Framework 4.0 x86 installed"); + return false; + } + + return true; + } +} diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/install/PackagesInstallerRunner.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/install/PackagesInstallerRunner.java index 39c9d0c..b633b0c 100644 --- a/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/install/PackagesInstallerRunner.java +++ b/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/install/PackagesInstallerRunner.java @@ -16,20 +16,20 @@ package jetbrains.buildServer.nuget.agent.runner.install; -import com.intellij.openapi.diagnostic.Logger; import jetbrains.buildServer.RunBuildException; -import jetbrains.buildServer.agent.*; +import jetbrains.buildServer.agent.AgentRunningBuild; +import jetbrains.buildServer.agent.BuildProcess; +import jetbrains.buildServer.agent.BuildRunnerContext; import jetbrains.buildServer.nuget.agent.commands.NuGetActionFactory; -import jetbrains.buildServer.nuget.agent.runner.install.impl.InstallStages; -import jetbrains.buildServer.nuget.agent.runner.install.impl.*; -import jetbrains.buildServer.nuget.agent.runner.install.impl.InstallStagesImpl; import jetbrains.buildServer.nuget.agent.parameters.NuGetFetchParameters; import jetbrains.buildServer.nuget.agent.parameters.PackagesInstallParameters; import jetbrains.buildServer.nuget.agent.parameters.PackagesParametersFactory; import jetbrains.buildServer.nuget.agent.parameters.PackagesUpdateParameters; +import jetbrains.buildServer.nuget.agent.runner.NuGetRunnerBase; +import jetbrains.buildServer.nuget.agent.runner.install.impl.InstallStages; +import jetbrains.buildServer.nuget.agent.runner.install.impl.InstallStagesImpl; import jetbrains.buildServer.nuget.agent.runner.install.impl.PackagesInstallerBuilder; import jetbrains.buildServer.nuget.agent.util.impl.CompositeBuildProcessImpl; -import jetbrains.buildServer.nuget.common.DotNetConstants; import jetbrains.buildServer.nuget.common.PackagesConstants; import org.jetbrains.annotations.NotNull; @@ -37,16 +37,10 @@ import org.jetbrains.annotations.NotNull; * Created by Eugene Petrenko (eugene.petrenko@gmail.com) * Date: 07.07.11 13:55 */ -public class PackagesInstallerRunner implements AgentBuildRunner, AgentBuildRunnerInfo { - private static final Logger LOG = Logger.getInstance(PackagesInstallerRunner.class.getName()); - - private final NuGetActionFactory myNuGetActionFactory; - private final PackagesParametersFactory myParametersFactory; - - public PackagesInstallerRunner(@NotNull final NuGetActionFactory nuGetActionFactory, +public class PackagesInstallerRunner extends NuGetRunnerBase { + public PackagesInstallerRunner(@NotNull final NuGetActionFactory actionFactory, @NotNull final PackagesParametersFactory parametersFactory) { - myNuGetActionFactory = nuGetActionFactory; - myParametersFactory = parametersFactory; + super(actionFactory, parametersFactory); } @NotNull @@ -72,7 +66,7 @@ public class PackagesInstallerRunner implements AgentBuildRunner, AgentBuildRunn parameters, context.getBuild().getBuildLogger(), new PackagesInstallerBuilder( - myNuGetActionFactory, + myActionFactory, stages, context, installParameters, @@ -82,27 +76,8 @@ public class PackagesInstallerRunner implements AgentBuildRunner, AgentBuildRunn stages.getLocateStage().pushBuildProcess(locate); } - @NotNull - public AgentBuildRunnerInfo getRunnerInfo() { - return this; - } - @NotNull public String getType() { return PackagesConstants.INSTALL_RUN_TYPE; } - - public boolean canRun(@NotNull BuildAgentConfiguration agentConfiguration) { - if (!agentConfiguration.getSystemInfo().isWindows()) { - LOG.warn("NuGet packages installer available only under windows"); - return false; - } - - if (!agentConfiguration.getConfigurationParameters().containsKey(DotNetConstants.DOT_NET_FRAMEWORK_4_x86)) { - LOG.warn("NuGet requires .NET Framework 4.0 x86 installed"); - return false; - } - - return true; - } } diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/install/PackagesInstallerRunnerRegistrar.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/install/PackagesInstallerRunnerRegistrar.java deleted file mode 100644 index e59c113..0000000 --- a/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/install/PackagesInstallerRunnerRegistrar.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2000-2011 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jetbrains.buildServer.nuget.agent.runner.install; - -import jetbrains.buildServer.agent.impl.BuildRunnerRegistry; -import org.jetbrains.annotations.NotNull; - -/** - * Created by Eugene Petrenko (eugene.petrenko@gmail.com) - * Date: 07.07.11 15:39 - */ -public class PackagesInstallerRunnerRegistrar { - public PackagesInstallerRunnerRegistrar(@NotNull final BuildRunnerRegistry reg, - @NotNull final PackagesInstallerRunner runner) { - reg.registerRunner(runner); - } -} diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/pack/PackRunner.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/pack/PackRunner.java index 622343d..e5e6e4d 100644 --- a/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/pack/PackRunner.java +++ b/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/pack/PackRunner.java @@ -16,15 +16,16 @@ package jetbrains.buildServer.nuget.agent.runner.pack; -import com.intellij.openapi.diagnostic.Logger; import jetbrains.buildServer.RunBuildException; -import jetbrains.buildServer.agent.*; +import jetbrains.buildServer.agent.AgentRunningBuild; +import jetbrains.buildServer.agent.BuildProcess; +import jetbrains.buildServer.agent.BuildRunnerContext; import jetbrains.buildServer.nuget.agent.commands.NuGetActionFactory; import jetbrains.buildServer.nuget.agent.parameters.NuGetPackParameters; import jetbrains.buildServer.nuget.agent.parameters.PackagesParametersFactory; +import jetbrains.buildServer.nuget.agent.runner.NuGetRunnerBase; import jetbrains.buildServer.nuget.agent.util.CompositeBuildProcess; import jetbrains.buildServer.nuget.agent.util.impl.CompositeBuildProcessImpl; -import jetbrains.buildServer.nuget.common.DotNetConstants; import jetbrains.buildServer.nuget.common.PackagesConstants; import org.jetbrains.annotations.NotNull; @@ -32,16 +33,10 @@ import org.jetbrains.annotations.NotNull; * @author Eugene Petrenko (eugene.petrenko@gmail.com) * Date: 23.08.11 12:11 */ -public class PackRunner implements AgentBuildRunner, AgentBuildRunnerInfo { - private static final Logger LOG = Logger.getInstance(PackRunner.class.getName()); - - private final NuGetActionFactory myActionFactory; - private final PackagesParametersFactory myParametersFactory; - +public class PackRunner extends NuGetRunnerBase { public PackRunner(@NotNull final NuGetActionFactory actionFactory, @NotNull final PackagesParametersFactory parametersFactory) { - myActionFactory = actionFactory; - myParametersFactory = parametersFactory; + super(actionFactory, parametersFactory); } @NotNull @@ -54,28 +49,8 @@ public class PackRunner implements AgentBuildRunner, AgentBuildRunnerInfo { return process; } - @NotNull - public AgentBuildRunnerInfo getRunnerInfo() { - return this; - } - @NotNull public String getType() { return PackagesConstants.PACK_RUN_TYPE; } - - public boolean canRun(@NotNull BuildAgentConfiguration agentConfiguration) { - if (!agentConfiguration.getSystemInfo().isWindows()) { - LOG.warn("NuGet packages installer available only under windows"); - return false; - } - - if (!agentConfiguration.getConfigurationParameters().containsKey(DotNetConstants.DOT_NET_FRAMEWORK_4_x86)) { - LOG.warn("NuGet requires .NET Framework 4.0 x86 installed"); - return false; - } - - return true; - } - } diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/pack/PackRunnerRegistrar.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/pack/PackRunnerRegistrar.java deleted file mode 100644 index 11abdc2..0000000 --- a/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/pack/PackRunnerRegistrar.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2000-2011 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jetbrains.buildServer.nuget.agent.runner.pack; - -import jetbrains.buildServer.agent.impl.BuildRunnerRegistry; -import org.jetbrains.annotations.NotNull; - -/** - * @author Eugene Petrenko (eugene.petrenko@gmail.com) - * Date: 23.08.11 12:13 - */ -public class PackRunnerRegistrar { - public PackRunnerRegistrar(@NotNull final BuildRunnerRegistry reg, - @NotNull final PackRunner runner) { - reg.registerRunner(runner); - } -} diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/publish/PackagesPublishRunner.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/publish/PackagesPublishRunner.java index 427bfa5..7266e59 100644 --- a/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/publish/PackagesPublishRunner.java +++ b/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/publish/PackagesPublishRunner.java @@ -16,15 +16,16 @@ package jetbrains.buildServer.nuget.agent.runner.publish; -import com.intellij.openapi.diagnostic.Logger; import jetbrains.buildServer.RunBuildException; -import jetbrains.buildServer.agent.*; +import jetbrains.buildServer.agent.AgentRunningBuild; +import jetbrains.buildServer.agent.BuildProcess; +import jetbrains.buildServer.agent.BuildRunnerContext; import jetbrains.buildServer.nuget.agent.commands.NuGetActionFactory; import jetbrains.buildServer.nuget.agent.parameters.NuGetPublishParameters; import jetbrains.buildServer.nuget.agent.parameters.PackagesParametersFactory; +import jetbrains.buildServer.nuget.agent.runner.NuGetRunnerBase; import jetbrains.buildServer.nuget.agent.util.CompositeBuildProcess; import jetbrains.buildServer.nuget.agent.util.impl.CompositeBuildProcessImpl; -import jetbrains.buildServer.nuget.common.DotNetConstants; import jetbrains.buildServer.nuget.common.PackagesConstants; import org.jetbrains.annotations.NotNull; @@ -34,16 +35,10 @@ import java.io.File; * Created by Eugene Petrenko (eugene.petrenko@gmail.com) * Date: 21.07.11 15:15 */ -public class PackagesPublishRunner implements AgentBuildRunner, AgentBuildRunnerInfo { - private static final Logger LOG = Logger.getInstance(PackagesPublishRunner.class.getName()); - - private final NuGetActionFactory myActionFactory; - private final PackagesParametersFactory myParametersFactory; - +public class PackagesPublishRunner extends NuGetRunnerBase { public PackagesPublishRunner(@NotNull final NuGetActionFactory actionFactory, @NotNull final PackagesParametersFactory parametersFactory) { - myActionFactory = actionFactory; - myParametersFactory = parametersFactory; + super(actionFactory, parametersFactory); } @NotNull @@ -63,27 +58,8 @@ public class PackagesPublishRunner implements AgentBuildRunner, AgentBuildRunner return process; } - @NotNull - public AgentBuildRunnerInfo getRunnerInfo() { - return this; - } - @NotNull public String getType() { return PackagesConstants.PUBLISH_RUN_TYPE; } - - public boolean canRun(@NotNull BuildAgentConfiguration agentConfiguration) { - if (!agentConfiguration.getSystemInfo().isWindows()) { - LOG.warn("NuGet packages installer available only under windows"); - return false; - } - - if (!agentConfiguration.getConfigurationParameters().containsKey(DotNetConstants.DOT_NET_FRAMEWORK_4_x86)) { - LOG.warn("NuGet requires .NET Framework 4.0 x86 installed"); - return false; - } - - return true; - } } \ No newline at end of file diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/publish/PackagesPublishRunnerRegistrar.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/publish/PackagesPublishRunnerRegistrar.java deleted file mode 100644 index 3226d1e..0000000 --- a/nuget-agent/src/jetbrains/buildServer/nuget/agent/runner/publish/PackagesPublishRunnerRegistrar.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2000-2011 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package jetbrains.buildServer.nuget.agent.runner.publish; - -import jetbrains.buildServer.agent.impl.BuildRunnerRegistry; -import org.jetbrains.annotations.NotNull; - -/** - * Created by Eugene Petrenko (eugene.petrenko@gmail.com) - * Date: 21.07.11 20:00 - */ -public class PackagesPublishRunnerRegistrar { - public PackagesPublishRunnerRegistrar(@NotNull final BuildRunnerRegistry reg, - @NotNull final PackagesPublishRunner runner) { - reg.registerRunner(runner); - } -} -- 2.23.3