Skip to content

Commit

Permalink
We have a simple server side support for the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
cprieto committed Mar 26, 2015
1 parent e720d3b commit 47449b1
Show file tree
Hide file tree
Showing 24 changed files with 591 additions and 1 deletion.
37 changes: 37 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,30 @@ allprojects {
repositories {
mavenCentral()
jcenter()

flatDir name: 'TeamCity', dir: TeamCity.replace("~", System.getProperty("user.home"))
}

jar {
appendix = "${rootProject.name}"
}

configurations {
plugin {
description = "Dependencies included with the plugin"
}
compile.extendsFrom(plugin)
}
}

task assemblePlugin(type: Zip) {
into ('server') {
from tasks.getByPath(':server:assemblePlugin').outputs.files
}

from ('.') {
include 'teamcity-plugin.xml'
}
}

project(":common") {
Expand All @@ -24,6 +43,24 @@ project(":common") {
}
}

project(':server') {
dependencies {
plugin project(':common')

compile name: 'common-api'
compile name: 'server-api'
compile 'com.intellij:annotations:+@jar'

testCompile 'org.testng:testng:+'
testCompile 'org.hamcrest:hamcrest-all:+'
testCompile 'org.mockito:mockito-core:1.+'
}

test {
useTestNG();
}
}

task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
9 changes: 9 additions & 0 deletions common/src/main/java/com/cprieto/octocity/common/Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.cprieto.octocity.common;

public final class Util {
private Util() {}

public static boolean IsNullOrWitespace(String input) {
return input == null || input.trim().length() == 0;
}
}
23 changes: 23 additions & 0 deletions common/src/test/java/com/cprieto/octocity/common/UtilTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.cprieto.octocity.common;

import org.testng.annotations.Test;
import static org.testng.Assert.*;

@Test
public class UtilTest {
public void testItCanValidateNullStrings(){
assertTrue(Util.IsNullOrWitespace(null));
}

public void testItCanValidateEmptyStrings() {
assertTrue(Util.IsNullOrWitespace(""));
}

public void testItCanVaidateOnlySpaceStrings() {
assertTrue(Util.IsNullOrWitespace(" "));
}

public void testItPassWithNonEmptyOrWhitespaceStrings() {
assertFalse(Util.IsNullOrWitespace("hola"));
}
}
5 changes: 5 additions & 0 deletions server/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
task assemblePlugin(type: Copy, dependsOn: jar) {
from project.configurations.plugin
from jar.outputs.files
into "${project.distsDir}/plugin"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.cprieto.octocity.server;

import com.cprieto.octocity.common.PropertyNames;

public class DescriptionPropertyValidator extends RequiredPropertyValidator {
public DescriptionPropertyValidator() {
super(PropertyNames.PACKAGE_DESCRIPTION, "Description cannot be empty");
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.cprieto.octocity.server;

import jetbrains.buildServer.serverSide.InvalidProperty;
import jetbrains.buildServer.serverSide.PropertiesProcessor;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

public class OctocityPropertyProcessor implements PropertiesProcessor {
private final List<PropertyValidator> validators;

public OctocityPropertyProcessor(@NotNull List<PropertyValidator> validators) {
this.validators = validators;
}

@Override
public Collection<InvalidProperty> process(@NotNull Map<String, String> properties) {
Collection<InvalidProperty> errors = new HashSet<InvalidProperty>();

for(PropertyValidator validator : validators) {
InvalidProperty result = validator.hasErrors(properties);
if (result != null) errors.add(result);
}

return errors;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.cprieto.octocity.server;

import com.cprieto.octocity.common.PluginConstants;
import com.cprieto.octocity.common.PropertyNames;
import jetbrains.buildServer.serverSide.Parameter;
import jetbrains.buildServer.serverSide.PropertiesProcessor;
import jetbrains.buildServer.serverSide.RunType;
import jetbrains.buildServer.serverSide.RunTypeRegistry;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Map;

public class OctocityRunType extends RunType {
private final OctocityPropertyProcessor processor;

public OctocityRunType(@NotNull final RunTypeRegistry registry, @NotNull OctocityPropertyProcessor processor) {
this.processor = processor;
registry.registerRunType(this);
}

@Override
public String getType() {
return PluginConstants.RUNNER_TYPE;
}

@Override
public String getDisplayName() {
return PluginConstants.RUNNER_NAME;
}

@Override
public String getDescription() {
return PluginConstants.RUNNER_DESCRIPTION;
}

@Override
public PropertiesProcessor getRunnerPropertiesProcessor() {
return processor;
}

@Override
public String getEditRunnerParamsJspFilePath() {
return ViewNames.EDIT_PARAMETERS;
}

@Override
public String getViewRunnerParamsJspFilePath() {
return ViewNames.VIEW_PARAMETERS;
}

@Override
public Map<String, String> getDefaultRunnerProperties() {
return new HashMap<String, String>() {{
put(PropertyNames.PACKAGE_VERSION, "%build.number%");
}};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.cprieto.octocity.server;

import com.cprieto.octocity.common.PropertyNames;

public class OwnersPropertyValidator extends RequiredPropertyValidator {

public OwnersPropertyValidator() {
super(PropertyNames.PACKAGE_OWNERS, "You need to tell us who is the package owner");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.cprieto.octocity.server;

import com.cprieto.octocity.common.PropertyNames;
import com.cprieto.octocity.common.Util;
import jetbrains.buildServer.serverSide.InvalidProperty;

import java.util.Map;

public class PackageIdValidator implements PropertyValidator {
@Override
public InvalidProperty hasErrors(Map<String, String> properties) {
String packageId = properties.get(PropertyNames.PACKAGE_ID);
if (Util.IsNullOrWitespace(packageId))
return new InvalidProperty(PropertyNames.PACKAGE_ID, "You need to specify a package id");

if (!packageId.matches("^[a-zA-Z.]+$"))
return new InvalidProperty(PropertyNames.PACKAGE_ID, "A valid package id can only contains letters and periods");

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.cprieto.octocity.server;

import com.cprieto.octocity.common.PropertyNames;
import com.cprieto.octocity.common.Util;
import jetbrains.buildServer.serverSide.InvalidProperty;
import org.jetbrains.annotations.NotNull;

import java.util.Map;

public class PackageVersionValidator implements PropertyValidator {
@Override
public InvalidProperty hasErrors(@NotNull Map<String, String> properties) {
String packageVersion = properties.get(PropertyNames.PACKAGE_VERSION);
if (Util.IsNullOrWitespace(packageVersion))
return new InvalidProperty(PropertyNames.PACKAGE_VERSION, "You need to specify a package version");

if (!packageVersion.matches("^(\\d+\\.)?(\\d+\\.)?(\\d+\\.)?(\\d+)$"))
return new InvalidProperty(PropertyNames.PACKAGE_VERSION, "Are you sure this is a valid package version?");

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.cprieto.octocity.server;

import jetbrains.buildServer.serverSide.InvalidProperty;
import org.jetbrains.annotations.NotNull;

import java.util.Map;

public interface PropertyValidator {
InvalidProperty hasErrors(@NotNull Map<String, String> properties);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.cprieto.octocity.server;

import com.cprieto.octocity.common.PropertyNames;
import com.cprieto.octocity.common.Util;
import jetbrains.buildServer.serverSide.InvalidProperty;
import org.jetbrains.annotations.NotNull;

import java.util.Map;

public abstract class RequiredPropertyValidator implements PropertyValidator {
private final String _propertyName;
private final String _errorMessage;

public RequiredPropertyValidator(String propertyName, String errorMessage) {
_propertyName = propertyName;
_errorMessage = errorMessage;
}

@Override
public InvalidProperty hasErrors(@NotNull Map<String, String> properties) {
if (Util.IsNullOrWitespace(properties.get(_propertyName)))
return new InvalidProperty(_propertyName, _errorMessage);
return null;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.cprieto.octocity.server;

public interface ViewNames {
String EDIT_PARAMETERS = "editParameters.jsp";
String VIEW_PARAMETERS = "viewParameters.jsp";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:lang="http://www.springframework.org/schema/lang" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/lang
http://www.springframework.org/schema/lang/spring-lang-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"
default-autowire="constructor">
<bean id="octocityRunType" class="com.cprieto.octocity.server.OctocityRunType">
<constructor-arg index="1" ref="octocityPropertyProcessor" />
</bean>
<bean id="octocityPropertyProcessor" class="com.cprieto.octocity.server.OctocityPropertyProcessor">
<constructor-arg>
<list>
<bean class="com.cprieto.octocity.server.DescriptionPropertyValidator"/>
<bean class="com.cprieto.octocity.server.OwnersPropertyValidator"/>
<bean class="com.cprieto.octocity.server.PackageIdValidator"/>
<bean class="com.cprieto.octocity.server.PackageVersionValidator"/>
</list>
</constructor-arg>
</bean>
</beans>
59 changes: 59 additions & 0 deletions server/src/main/resources/buildServerResources/editParameters.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<%@ taglib prefix="props" tagdir="/WEB-INF/tags/props" %>
<%@ taglib prefix="forms" tagdir="/WEB-INF/tags/forms" %>
<%@ taglib prefix="l" tagdir="/WEB-INF/tags/layout" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<jsp:useBean id="propertiesBean" scope="request" type="jetbrains.buildServer.controllers.BasePropertiesBean"/>

<l:settingsGroup title="Octopus Nuget Package properties">
<tr>
<th>
<label for="octocity.id">Package id: <l:star/></label>
</th>
<td>
<props:textProperty name="octocity.id" className="longField" />
<span class="error" id="error_octocity.id"></span>
<span class="smallNote">Package identifier (eg. package.id)</span>
</td>
</tr>
<tr>
<th>
<label for="octocity.title">Title: </label>
</th>
<td>
<props:textProperty name="octocity.title" className="longField" />
<span class="error" id="error_octocity.title"></span>
<span class="smallNote">Package title (eg. 'This is an awesome package')</span>
</td>
</tr>
<tr>
<th>
<label for="octocity.version">Version: <l:star/></label>
</th>
<td>
<props:textProperty name="octocity.version" className="longField" />
<span class="error" id="error_octocity.version"></span>
<span class="smallNote">Package version (eg. 1.2.3)</span>
</td>
</tr>
<tr>
<th>
<label for="octocity.owners">Onwers: <l:star/></label>
</th>
<td>
<props:textProperty name="octocity.owners" className="longField" />
<span class="error" id="error_octocity.owners"></span>
<span class="smallNote">Package owners (eg. 'superman, batman')</span>
</td>
</tr>
<tr>
<th>
<label for="octocity.description">Description: <l:star/></label>
</th>
<td>
<props:textProperty name="octocity.description" className="longField" />
<span class="error" id="error_octocity.description"></span>
<span class="smallNote">Package description (eg. 'This is a nice deployment package')</span>
</td>
</tr>
</l:settingsGroup>
Empty file.
Loading

0 comments on commit 47449b1

Please sign in to comment.