more infrastructure:
authorEugene.Petrenko <eugene.petrenko@gmail.com>
Thu, 7 Jul 2011 11:42:39 +0000 (15:42 +0400)
committerEugene.Petrenko <eugene.petrenko@gmail.com>
Thu, 7 Jul 2011 11:42:39 +0000 (15:42 +0400)
PackgesIntallerRunner,
utilities to run more than one commandline's from one runner
shared interfaces

.idea/libraries/Agent_internal.xml [new file with mode: 0644]
nuget-agent/nuget-agent.iml
nuget-agent/src/META-INF/build-agent-plugin-nuget.xml
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackagesInstallerRunner.java [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackagesInstallerRunnerRegistrar.java [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/util/CommandlineBuildProcessFactory.java [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/util/CompositeBuildProcess.java [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/util/impl/CommandlineBuildProcessFactoryImpl.java [new file with mode: 0644]
nuget-agent/src/jetbrains/buildServer/nuget/agent/util/impl/CompositeBuildProcessImpl.java [new file with mode: 0644]
nuget-common/src/jetbrains/buildServer/nuget/common/DotNetConstants.java [new file with mode: 0644]
nuget-common/src/jetbrains/buildServer/nuget/common/PackagesInstallerConstants.java [new file with mode: 0644]

diff --git a/.idea/libraries/Agent_internal.xml b/.idea/libraries/Agent_internal.xml
new file mode 100644 (file)
index 0000000..ef71ed0
--- /dev/null
@@ -0,0 +1,9 @@
+<component name="libraryTable">\r
+  <library name="Agent-internal">\r
+    <CLASSES>\r
+      <root url="jar://$TeamCityDistribution$/buildAgent/lib/agent.jar!/" />\r
+    </CLASSES>\r
+    <JAVADOC />\r
+    <SOURCES />\r
+  </library>\r
+</component>
\ No newline at end of file
index 86d7fcfaa0b6083fa89c8a525c5d6fbb44dc7c96..cc860cd7e39939e563933995e2a9d24b010af100 100644 (file)
@@ -5,6 +5,8 @@
       <configuration>\r
         <fileset id="fileset1" name="nuget-agent" removed="false">\r
           <file>file://$MODULE_DIR$/src/META-INF/build-agent-plugin-nuget.xml</file>\r
+          <file>jar://$TeamCityDistribution$/buildAgent/lib/agent.jar!/META-INF/buildAgentSpring.xml</file>\r
+          <file>jar://$TeamCityDistribution$/buildAgent/lib/agent.jar!/META-INF/buildAgentPlugins.xml</file>\r
         </fileset>\r
       </configuration>\r
     </facet>\r
     </content>\r
     <orderEntry type="inheritedJdk" />\r
     <orderEntry type="sourceFolder" forTests="false" />\r
+    <orderEntry type="library" name="Agent-Api" level="project" />\r
+    <orderEntry type="library" name="Common-Api" level="project" />\r
+    <orderEntry type="library" name="Idea-OpenApi" level="project" />\r
+    <orderEntry type="library" name="log4j" level="project" />\r
+    <orderEntry type="module" module-name="nuget-common" />\r
+    <orderEntry type="library" name="Agent-internal" level="project" />\r
   </component>\r
 </module>\r
 \r
index 7f2cd89a51e8084fc69e25f780896582d556930e..96cd105dd09714a4a08d5e985b3a2dfe2cf659f9 100644 (file)
@@ -4,4 +4,8 @@
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"\r
        default-autowire="constructor">\r
 \r
+  <bean class="jetbrains.buildServer.nuget.agent.util.impl.CommandlineBuildProcessFactoryImpl"/>\r
+\r
+  <bean class="jetbrains.buildServer.nuget.agent.install.PackagesInstallerRunner"/>\r
+  <bean class="jetbrains.buildServer.nuget.agent.install.PackagesInstallerRunnerRegistrar"/>\r
 </beans>
\ No newline at end of file
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackagesInstallerRunner.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackagesInstallerRunner.java
new file mode 100644 (file)
index 0000000..c1906bf
--- /dev/null
@@ -0,0 +1,64 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.agent.install;\r
+\r
+import com.intellij.openapi.diagnostic.Logger;\r
+import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.agent.*;\r
+import jetbrains.buildServer.nuget.common.DotNetConstants;\r
+import jetbrains.buildServer.nuget.common.PackagesInstallerConstants;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 07.07.11 13:55\r
+ */\r
+public class PackagesInstallerRunner implements AgentBuildRunner, AgentBuildRunnerInfo{\r
+  private static final Logger LOG = Logger.getInstance(PackagesInstallerRunner.class.getName());\r
+\r
+  @NotNull\r
+  public BuildProcess createBuildProcess(@NotNull AgentRunningBuild runningBuild,\r
+                                         @NotNull BuildRunnerContext context) throws RunBuildException {\r
+\r
+    throw new RunBuildException("Not Implemented");\r
+  }\r
+\r
+  @NotNull\r
+  public AgentBuildRunnerInfo getRunnerInfo() {\r
+    return this;\r
+  }\r
+\r
+  @NotNull\r
+  public String getType() {\r
+    return PackagesInstallerConstants.RUN_TYPE;\r
+  }\r
+\r
+  public boolean canRun(@NotNull BuildAgentConfiguration agentConfiguration) {\r
+    if (!agentConfiguration.getSystemInfo().isWindows()) {\r
+      LOG.warn("NuGet packages installer available only under windows");\r
+      return false;\r
+    }\r
+\r
+    if (!agentConfiguration.getConfigurationParameters().containsKey(DotNetConstants.DOT_NET_FRAMEWORK_4_x86)) {\r
+      LOG.warn("NuGet requires .NET Framework 4.0 x86 installed");\r
+      return false;\r
+    }\r
+\r
+    return true;\r
+  }\r
+\r
+}\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackagesInstallerRunnerRegistrar.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/install/PackagesInstallerRunnerRegistrar.java
new file mode 100644 (file)
index 0000000..78b71b7
--- /dev/null
@@ -0,0 +1,31 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.agent.install;\r
+\r
+import jetbrains.buildServer.agent.impl.BuildRunnerRegistry;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 07.07.11 15:39\r
+ */\r
+public class PackagesInstallerRunnerRegistrar {\r
+  public PackagesInstallerRunnerRegistrar(@NotNull final BuildRunnerRegistry reg,\r
+                                          @NotNull final PackagesInstallerRunner runner) {\r
+    reg.registerRunner(runner);\r
+  }\r
+}\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/util/CommandlineBuildProcessFactory.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/util/CommandlineBuildProcessFactory.java
new file mode 100644 (file)
index 0000000..ba6db1d
--- /dev/null
@@ -0,0 +1,16 @@
+package jetbrains.buildServer.nuget.agent.util;\r
+\r
+import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.agent.BuildProcess;\r
+import jetbrains.buildServer.agent.BuildRunnerContext;\r
+import jetbrains.buildServer.agent.runner.ProgramCommandLine;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 07.07.11 15:36\r
+ */\r
+public interface CommandlineBuildProcessFactory {\r
+  BuildProcess executeCommandLine(@NotNull BuildRunnerContext hostContext,\r
+                                  @NotNull ProgramCommandLine cmd) throws RunBuildException;\r
+}\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/util/CompositeBuildProcess.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/util/CompositeBuildProcess.java
new file mode 100644 (file)
index 0000000..ff4e1c3
--- /dev/null
@@ -0,0 +1,12 @@
+package jetbrains.buildServer.nuget.agent.util;\r
+\r
+import jetbrains.buildServer.agent.BuildProcess;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 07.07.11 15:37\r
+ */\r
+public interface CompositeBuildProcess extends BuildProcess {\r
+  void pushBuildProcess(@NotNull BuildProcess process);\r
+}\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/util/impl/CommandlineBuildProcessFactoryImpl.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/util/impl/CommandlineBuildProcessFactoryImpl.java
new file mode 100644 (file)
index 0000000..deeb1ad
--- /dev/null
@@ -0,0 +1,96 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.agent.util.impl;\r
+\r
+import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.agent.BuildProcess;\r
+import jetbrains.buildServer.agent.BuildProcessFacade;\r
+import jetbrains.buildServer.agent.BuildRunnerContext;\r
+import jetbrains.buildServer.agent.runner.ProgramCommandLine;\r
+import jetbrains.buildServer.nuget.agent.util.CommandlineBuildProcessFactory;\r
+import jetbrains.buildServer.runner.SimpleRunnerConstants;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+import java.util.Collection;\r
+import java.util.Map;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 07.07.11 15:13\r
+ */\r
+public class CommandlineBuildProcessFactoryImpl implements CommandlineBuildProcessFactory {\r
+  private final BuildProcessFacade myFacade;\r
+\r
+  public CommandlineBuildProcessFactoryImpl(@NotNull final BuildProcessFacade facade) {\r
+    myFacade = facade;\r
+  }\r
+\r
+  public BuildProcess executeCommandLine(@NotNull final BuildRunnerContext hostContext,\r
+                                         @NotNull final ProgramCommandLine cmd) throws RunBuildException {\r
+    BuildRunnerContext context = myFacade.createBuildRunnerContext(\r
+            hostContext.getBuild(),\r
+            SimpleRunnerConstants.TYPE,\r
+            cmd.getWorkingDirectory(),\r
+            hostContext\r
+    );\r
+\r
+    context.addRunnerParameter(SimpleRunnerConstants.COMMAND_EXECUTABLE, cmd.getExecutablePath());\r
+    context.addRunnerParameter(SimpleRunnerConstants.COMMAND_PARAMETERS, joinCommandLineArguments(cmd.getArguments()));\r
+\r
+    for (Map.Entry<String, String> e : cmd.getEnvironment().entrySet()) {\r
+      context.addEnvironmentVariable(e.getKey(), e.getValue());\r
+    }\r
+\r
+    return myFacade.createExecutable(hostContext.getBuild(), context);\r
+  }\r
+\r
+  //This is a same code as system uses in ProcessImpl class\r
+  private String joinCommandLineArguments(@NotNull final Collection<String> cmd) {\r
+    StringBuilder cmdbuf = new StringBuilder(80);\r
+    boolean isFirst = true;\r
+    for (String aCmd : cmd) {\r
+      if (!isFirst) {\r
+        cmdbuf.append(' ');\r
+      } else {\r
+        isFirst = false;\r
+      }\r
+      if (aCmd.indexOf(' ') < 0 && aCmd.indexOf('\t') < 0) {\r
+        cmdbuf.append(aCmd);\r
+        continue;\r
+      }\r
+\r
+      if (aCmd.charAt(0) != '"') {\r
+        cmdbuf.append('"');\r
+        cmdbuf.append(aCmd);\r
+\r
+        if (aCmd.endsWith("\\")) {\r
+          cmdbuf.append("\\");\r
+        }\r
+\r
+        cmdbuf.append('"');\r
+      } else if (aCmd.endsWith("\"")) {\r
+        /* The argument has already been quoted. */\r
+        cmdbuf.append(aCmd);\r
+      } else {\r
+        /* Unmatched quote for the argument. */\r
+        throw new IllegalArgumentException();\r
+      }\r
+    }\r
+    return cmdbuf.toString();\r
+  }\r
+\r
+}\r
diff --git a/nuget-agent/src/jetbrains/buildServer/nuget/agent/util/impl/CompositeBuildProcessImpl.java b/nuget-agent/src/jetbrains/buildServer/nuget/agent/util/impl/CompositeBuildProcessImpl.java
new file mode 100644 (file)
index 0000000..9dda19c
--- /dev/null
@@ -0,0 +1,81 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.agent.util.impl;\r
+\r
+import jetbrains.buildServer.RunBuildException;\r
+import jetbrains.buildServer.agent.BuildFinishedStatus;\r
+import jetbrains.buildServer.agent.BuildProcess;\r
+import jetbrains.buildServer.nuget.agent.util.CompositeBuildProcess;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+import java.util.concurrent.BlockingQueue;\r
+import java.util.concurrent.LinkedBlockingQueue;\r
+import java.util.concurrent.atomic.AtomicBoolean;\r
+import java.util.concurrent.atomic.AtomicReference;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 07.07.11 14:04\r
+ */\r
+public class CompositeBuildProcessImpl implements CompositeBuildProcess {\r
+  private final BlockingQueue<BuildProcess> myProcessList = new LinkedBlockingQueue<BuildProcess>();\r
+  private final AtomicBoolean myIsInterrupted = new AtomicBoolean();\r
+  private final AtomicBoolean myIsFinished = new AtomicBoolean();\r
+  private final AtomicReference<BuildProcess> myCurrentProcess = new AtomicReference<BuildProcess>();\r
+\r
+  public void pushBuildProcess(@NotNull final BuildProcess process) {\r
+    myProcessList.add(process);\r
+  }\r
+\r
+  public void start() throws RunBuildException {\r
+  }\r
+\r
+  public boolean isInterrupted() {\r
+    return myIsInterrupted.get();\r
+  }\r
+\r
+  public boolean isFinished() {\r
+    return myIsFinished.get();\r
+  }\r
+\r
+  public void interrupt() {\r
+    myIsInterrupted.set(true);\r
+    BuildProcess process = myCurrentProcess.get();\r
+    if (process != null) {\r
+      process.interrupt();\r
+    }\r
+  }\r
+\r
+  @NotNull\r
+  public BuildFinishedStatus waitFor() throws RunBuildException {\r
+    for(BuildProcess proc = myProcessList.poll(); proc != null; proc = myProcessList.poll()) {\r
+      myCurrentProcess.set(proc);\r
+      try {\r
+        proc.start();\r
+        BuildFinishedStatus status = proc.waitFor();\r
+        if (status == BuildFinishedStatus.FINISHED_FAILED ) return BuildFinishedStatus.FINISHED_FAILED;\r
+      } finally {\r
+        myCurrentProcess.set(null);\r
+      }\r
+      if (isInterrupted()) return BuildFinishedStatus.INTERRUPTED;\r
+    }\r
+    myIsFinished.set(true);\r
+    if (isInterrupted()) return BuildFinishedStatus.INTERRUPTED;\r
+\r
+    return BuildFinishedStatus.FINISHED_SUCCESS;\r
+  }\r
+}\r
diff --git a/nuget-common/src/jetbrains/buildServer/nuget/common/DotNetConstants.java b/nuget-common/src/jetbrains/buildServer/nuget/common/DotNetConstants.java
new file mode 100644 (file)
index 0000000..2162852
--- /dev/null
@@ -0,0 +1,28 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.common;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 07.07.11 13:58\r
+ */\r
+public interface DotNetConstants {\r
+  //NOTE: This is an implicit dependency to .NET runners agent plugin.\r
+  //NOTE: For now there is no chance to share classes between plugins.\r
+  public static final String DOT_NET_FRAMEWORK_4_x86 = "DotNetFramework4.0_x86";\r
+  public static final String DOT_NET_FRAMEWORK_4_x64 = "DotNetFramework4.0_x64";\r
+}\r
diff --git a/nuget-common/src/jetbrains/buildServer/nuget/common/PackagesInstallerConstants.java b/nuget-common/src/jetbrains/buildServer/nuget/common/PackagesInstallerConstants.java
new file mode 100644 (file)
index 0000000..a9bada1
--- /dev/null
@@ -0,0 +1,25 @@
+/*\r
+ * Copyright 2000-2011 JetBrains s.r.o.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package jetbrains.buildServer.nuget.common;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 07.07.11 13:56\r
+ */\r
+public interface PackagesInstallerConstants {\r
+  public static final String RUN_TYPE = "jetbrains.nuget.packagesInstaller";\r
+}\r