introduce nuget settings UI, reuse nuget path from it
authorEugene Petrenko <eugene.petrenko@gmail.com>
Tue, 16 Aug 2011 07:29:14 +0000 (11:29 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Tue, 16 Aug 2011 07:29:14 +0000 (11:29 +0400)
nuget-server/resources/install/editInstallPackage.jsp
nuget-server/resources/publish/editPublish.jsp
nuget-server/resources/tool/runnerSettings.jsp [new file with mode: 0644]
nuget-server/resources/trigger/editSimpleTrigger.jsp
nuget-server/src/META-INF/build-server-plugin-nuget-tools.xml
nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/tab/ServerSettingsTab.java
nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/ui/ToolInfo.java [new file with mode: 0644]
nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/ui/ToolSelectorController.java [new file with mode: 0644]

index e43df9bad929c73b2f3b9a80ea9830405b5f5be9..75e4fd53649086f590f8b0aa70170be77467cd80 100644 (file)
 \r
 <l:settingsGroup title="NuGet settings">\r
   <tr>\r
-    <th>Path to NuGet.exe<l:star/></th>\r
+    <th>NuGet.exe<l:star/></th>\r
     <td>\r
-      <props:textProperty name="${ib.nuGetPathKey}" className="longField"/>\r
-      <span class="smallNote">Specify path to NuGet.exe</span>\r
-      <span class="error" id="error_${ib.nuGetPathKey}"></span>\r
+      <jsp:include page="../tool/runnerSettings.html?name=${ib.nuGetPathKey}&class=longField"/>\r
     </td>\r
   </tr>\r
   <tr>\r
index ac03468c2a7ccbab2451ecf9be6e0e00b148448f..5ad8e79fbd0f1049bab5eb3dceb3d4934364be44 100644 (file)
 \r
 <l:settingsGroup title="NuGet settings">\r
   <tr>\r
-    <th>Path to NuGet.exe<l:star/></th>\r
+    <th>NuGet.exe<l:star/></th>\r
     <td>\r
-      <props:textProperty name="${ib.nuGetPathKey}" className="longField"/>\r
-      <span class="smallNote">Specify path to NuGet.exe</span>\r
-      <span class="error" id="error_${ib.nuGetPathKey}"></span>\r
+      <jsp:include page="../tool/runnerSettings.html?name=${ib.nuGetPathKey}&class=longField"/>\r
     </td>\r
   </tr>\r
   <tr>\r
diff --git a/nuget-server/resources/tool/runnerSettings.jsp b/nuget-server/resources/tool/runnerSettings.jsp
new file mode 100644 (file)
index 0000000..6d37cdf
--- /dev/null
@@ -0,0 +1,44 @@
+<%--\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
+<%@ include file="/include-internal.jsp"%>\r
+<%@ taglib prefix="forms" tagdir="/WEB-INF/tags/forms" %>\r
+<%@ taglib prefix="props" tagdir="/WEB-INF/tags/props" %>\r
+<%@ taglib prefix="l" tagdir="/WEB-INF/tags/layout" %>\r
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>\r
+<jsp:useBean id="name" scope="request" type="java.lang.String"/>\r
+<jsp:useBean id="clazz" scope="request" type="java.lang.String"/>\r
+<jsp:useBean id="style" scope="request" type="java.lang.String"/>\r
+<jsp:useBean id="value" scope="request" type="java.lang.String"/>\r
+<jsp:useBean id="settingsUrl" scope="request" type="java.lang.String"/>\r
+<jsp:useBean id="items" scope="request" type="java.util.Collection<jetbrains.buildServer.nuget.server.toolRegistry.ui.ToolInfo >"/>\r
+\r
+<props:selectProperty name="${name}" className="${clazz}" style="${style}">\r
+  <c:set var="isSelected" value="${value eq ''}"/>\r
+  <props:option value="" selected="${isSelected}">-- Select NuGet version to run --</props:option>\r
+  <c:set var="hasSelected" value="${isSelected}"/>\r
+  <c:forEach var="it" items="${items}">\r
+    <c:set var="isSelected" value="${it.id eq value}"/>\r
+    <props:option value="${it.id}" selected="${isSelected}"><c:out value="${it.version}"/></props:option>\r
+    <c:if test="${isSelected}"><c:set var="hasSelected" value="${true}"/></c:if>\r
+  </c:forEach>\r
+  <c:if test="${not hasSelected}">\r
+    <props:option value="${value}" selected="${true}">Custom: <c:out value="${value}"/></props:option>\r
+  </c:if>\r
+</props:selectProperty>\r
+<span class="smallNote">Specify NuGet.exe version.\r
+  Check intalled NuGet Commandline tools in <a href="<c:url value="${settingsUrl}"/>">NuGet Settings</a>\r
+</span>\r
+<span class="error" id="error_${name}"></span>\r
index 2fdbd7c97071737a6567be163a8d1b24613ff9cd..727b447cbc8b7430bbad5432d73f018609bc1de0 100644 (file)
 <jsp:useBean id="ib" class="jetbrains.buildServer.nuget.server.trigger.TriggerBean" scope="request"/>\r
 \r
 <tr>\r
-  <td>NuGet path:<l:star/></td>\r
+  <th>NuGet.exe<l:star/></th>\r
   <td>\r
-    <props:textProperty name="${ib.nuGetExeKey}" style="width:20em;" />\r
-    <span class="smallNote">Specify path to NuGet.exe </span>\r
-    <span class="error" id="error_${ib.sourceKey}"></span>\r
+    <jsp:include page="../tool/runnerSettings.html?name=${ib.nuGetExeKey}&style=width:20em"/>\r
   </td>\r
 </tr>\r
 \r
index 990310cca576a4d74ae3ffb541829cb182255ffd..59c2c3461603583cc45d9016b50403608fa711b9 100644 (file)
@@ -3,6 +3,8 @@
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"\r
        default-autowire="constructor">\r
+  <bean class="jetbrains.buildServer.nuget.server.toolRegistry.ui.ToolSelectorController"/>\r
+\r
   <bean class="jetbrains.buildServer.nuget.server.toolRegistry.tab.PermissionChecker"/>\r
   <bean class="jetbrains.buildServer.nuget.server.toolRegistry.tab.ServerSettingsTab"/>\r
   <bean class="jetbrains.buildServer.nuget.server.toolRegistry.tab.InstalledToolsController"/>\r
index 91a4c2628850167e075ba6d6d69544497aacd5f5..6efd6465347fc5db196b9abd139a659839ffc76f 100644 (file)
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.NotNull;
  * Date: 10.08.11 20:35\r
  */\r
 public class ServerSettingsTab extends SimpleCustomTab {\r
+  public static final String TAB_ID = "nugetServerSettingsTab";\r
   private final PermissionChecker myChecker;\r
 \r
   public ServerSettingsTab(@NotNull final PagePlaces pagePlaces,\r
@@ -32,7 +33,7 @@ public class ServerSettingsTab extends SimpleCustomTab {
                            @NotNull final PermissionChecker checker) {\r
     super(pagePlaces,\r
             PlaceId.ADMIN_SERVER_CONFIGURATION_TAB,\r
-            "nugetServerSettingsTab",\r
+            TAB_ID,\r
             controller.getPath(),\r
             "NuGet");\r
     myChecker = checker;\r
diff --git a/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/ui/ToolInfo.java b/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/ui/ToolInfo.java
new file mode 100644 (file)
index 0000000..9b73da7
--- /dev/null
@@ -0,0 +1,49 @@
+/*\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.server.toolRegistry.ui;\r
+\r
+import jetbrains.buildServer.nuget.server.toolRegistry.NuGetInstalledTool;\r
+import org.jetbrains.annotations.NotNull;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 16.08.11 11:00\r
+ */\r
+public class ToolInfo {\r
+  private final String myId;\r
+  private final String myVersion;\r
+\r
+  public ToolInfo(@NotNull final NuGetInstalledTool tool) {\r
+    this("?" + tool.getId(), tool.getVersion());\r
+  }\r
+\r
+  public ToolInfo(@NotNull final String id,\r
+                  @NotNull final String version) {\r
+    myId = id;\r
+    myVersion = version;\r
+  }\r
+\r
+  @NotNull\r
+  public String getId() {\r
+    return myId;\r
+  }\r
+\r
+  @NotNull\r
+  public String getVersion() {\r
+    return myVersion;\r
+  }\r
+}\r
diff --git a/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/ui/ToolSelectorController.java b/nuget-server/src/jetbrains/buildServer/nuget/server/toolRegistry/ui/ToolSelectorController.java
new file mode 100644 (file)
index 0000000..3627b16
--- /dev/null
@@ -0,0 +1,115 @@
+/*\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.server.toolRegistry.ui;\r
+\r
+import jetbrains.buildServer.controllers.BaseController;\r
+import jetbrains.buildServer.controllers.BasePropertiesBean;\r
+import jetbrains.buildServer.nuget.server.toolRegistry.NuGetInstalledTool;\r
+import jetbrains.buildServer.nuget.server.toolRegistry.NuGetToolManager;\r
+import jetbrains.buildServer.nuget.server.toolRegistry.tab.ServerSettingsTab;\r
+import jetbrains.buildServer.util.StringUtil;\r
+import jetbrains.buildServer.web.openapi.PluginDescriptor;\r
+import jetbrains.buildServer.web.openapi.WebControllerManager;\r
+import org.jetbrains.annotations.NotNull;\r
+import org.jetbrains.annotations.Nullable;\r
+import org.springframework.web.servlet.ModelAndView;\r
+\r
+import javax.servlet.http.HttpServletRequest;\r
+import javax.servlet.http.HttpServletResponse;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+\r
+/**\r
+ * Created by Eugene Petrenko (eugene.petrenko@gmail.com)\r
+ * Date: 16.08.11 10:21\r
+ */\r
+public class ToolSelectorController extends BaseController {\r
+  private final NuGetToolManager myToolManager;\r
+  private final PluginDescriptor myDescriptor;\r
+  private final String myPath;\r
+\r
+  public ToolSelectorController(@NotNull final NuGetToolManager toolManager,\r
+                                @NotNull final PluginDescriptor descriptor,\r
+                                @NotNull final WebControllerManager web) {\r
+    myToolManager = toolManager;\r
+    myDescriptor = descriptor;\r
+    myPath = descriptor.getPluginResourcesPath("tool/runnerSettings.html");\r
+    web.registerController(myPath, this);\r
+  }\r
+\r
+  @NotNull\r
+  public String getPath() {\r
+    return myPath;\r
+  }\r
+\r
+  @Override\r
+  protected ModelAndView doHandle(HttpServletRequest request, HttpServletResponse response) throws Exception {\r
+    final String name = safe(request.getParameter("name"));\r
+    String value = parseValue(request, name);\r
+    final Collection<ToolInfo> tools = getTools();\r
+    ensureVersion(value, tools);\r
+\r
+\r
+    ModelAndView mv = new ModelAndView(myDescriptor.getPluginResourcesPath("tool/runnerSettings.jsp"));\r
+    mv.getModel().put("name", name);\r
+    mv.getModel().put("value", value);\r
+    mv.getModel().put("clazz", safe(request.getParameter("class")));\r
+    mv.getModel().put("style", safe(request.getParameter("style")));\r
+    mv.getModel().put("items", tools);\r
+    mv.getModel().put("settingsUrl", "/admin/serverConfig.html?init=1&tab=" + ServerSettingsTab.TAB_ID);\r
+    return mv;\r
+  }\r
+\r
+  private void ensureVersion(@NotNull final String version, @NotNull Collection<ToolInfo> actionInfos) {\r
+    if (!version.startsWith("?")) return;\r
+    for (ToolInfo actionInfo : actionInfos) {\r
+      if (actionInfo.getId().equals(version)) return;\r
+    }\r
+    actionInfos.add(new ToolInfo(version, "Not Installed: " + version.substring(1)));\r
+  }\r
+\r
+  @NotNull\r
+  private Collection<ToolInfo> getTools() {\r
+    final ArrayList<ToolInfo> result = new ArrayList<ToolInfo>();\r
+    for (NuGetInstalledTool nuGetInstalledTool : myToolManager.getInstalledTools()) {\r
+      result.add(new ToolInfo(nuGetInstalledTool));\r
+    }\r
+    return result;\r
+  }\r
+\r
+  private static String safe(@Nullable String s) {\r
+    if (StringUtil.isEmptyOrSpaces(s)) return "";\r
+    return s;\r
+  }\r
+\r
+  @NotNull\r
+  private String parseValue(HttpServletRequest request, String name) {\r
+    String value = null;\r
+\r
+    final BasePropertiesBean bean = (BasePropertiesBean)request.getAttribute("propertiesBean");\r
+    if (bean != null) {\r
+      value = bean.getProperties().get(name);\r
+    }\r
+    if (value == null) {\r
+      value = request.getParameter("value");\r
+    }\r
+    if (value == null) {\r
+      value = "";\r
+    }\r
+    return value;\r
+  }\r
+}\r