Search in sources :

Example 6 with Property

use of com.thoughtworks.go.domain.Property in project gocd by gocd.

the class PropertiesServiceTest method shouldGenerateFromProperties.

@Test
public void shouldGenerateFromProperties() throws Exception {
    Properties props = new Properties(new Property("a", "1"), new Property("b", "2"));
    Csv csv = PropertiesService.fromProperties(props);
    assertThat(csv.toString(), is("a,b\n" + "1,2\n"));
}
Also used : Csv(com.thoughtworks.go.util.Csv) Properties(com.thoughtworks.go.domain.Properties) Property(com.thoughtworks.go.domain.Property) Test(org.junit.Test)

Example 7 with Property

use of com.thoughtworks.go.domain.Property in project gocd by gocd.

the class PropertiesServiceTest method shouldGenerateFromHistoryOfProperties.

@Test
public void shouldGenerateFromHistoryOfProperties() throws Exception {
    List<Properties> history = new ArrayList<>();
    history.add(new Properties(new Property("a", "100"), new Property("b", "200")));
    history.add(new Properties(new Property("a", "300"), new Property("b", "400")));
    Csv csv = PropertiesService.fromAllPropertiesHistory(history);
    assertThat(csv.toString(), is("a,b\n" + "100,200\n" + "300,400\n"));
}
Also used : Csv(com.thoughtworks.go.util.Csv) ArrayList(java.util.ArrayList) Properties(com.thoughtworks.go.domain.Properties) Property(com.thoughtworks.go.domain.Property) Test(org.junit.Test)

Example 8 with Property

use of com.thoughtworks.go.domain.Property in project gocd by gocd.

the class PropertiesServiceTest method shouldLoadOriginalJobPropertiesForGivenJobIdentifier.

@Test
public void shouldLoadOriginalJobPropertiesForGivenJobIdentifier() {
    Properties props = new Properties(new Property("a", "1"), new Property("b", "2"));
    PropertyDao propertyDao = mock(PropertyDao.class);
    JobResolverService resolver = mock(JobResolverService.class);
    PropertiesService service = new PropertiesService(propertyDao, null, null, resolver);
    JobIdentifier oldId = new JobIdentifier("pipeline-name", 10, "label-10", "stage-name", "3", "job-name", 9l);
    when(propertyDao.list(6l)).thenReturn(props);
    when(resolver.actualJobIdentifier(oldId)).thenReturn(new JobIdentifier("pipeline-name", 7, "label-7", "stage-name", "1", "job-name", 6l));
    assertThat(service.getPropertiesForOriginalJob(oldId), is(props));
}
Also used : PropertyDao(com.thoughtworks.go.server.dao.PropertyDao) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Properties(com.thoughtworks.go.domain.Properties) Property(com.thoughtworks.go.domain.Property) Test(org.junit.Test)

Example 9 with Property

use of com.thoughtworks.go.domain.Property in project gocd by gocd.

the class ArtifactPropertiesGenerator method generate.

public void generate(GoPublisher publisher, File buildWorkingDirectory) {
    File file = new File(buildWorkingDirectory, getSrc());
    String indent = "             ";
    if (!file.exists()) {
        publisher.consumeLine(format("%sFailed to create property %s. File %s does not exist.", indent, getName(), file.getAbsolutePath()));
    } else {
        try {
            if (!XpathUtils.nodeExists(file, getXpath())) {
                publisher.consumeLine(format("%sFailed to create property %s. Nothing matched xpath \"%s\" in the file: %s.", indent, getName(), getXpath(), file.getAbsolutePath()));
            } else {
                String value = XpathUtils.evaluate(file, getXpath());
                publisher.setProperty(new Property(getName(), value));
                publisher.consumeLine(format("%sProperty %s = %s created." + "\n", indent, getName(), value));
            }
        } catch (Exception e) {
            String error = (e instanceof XPathExpressionException) ? (format("Illegal xpath: \"%s\"", getXpath())) : ExceptionUtils.messageOf(e);
            String message = format("%sFailed to create property %s. %s", indent, getName(), error);
            publisher.reportErrorMessage(message, e);
        }
    }
}
Also used : XPathExpressionException(javax.xml.xpath.XPathExpressionException) File(java.io.File) Property(com.thoughtworks.go.domain.Property) XPathExpressionException(javax.xml.xpath.XPathExpressionException)

Example 10 with Property

use of com.thoughtworks.go.domain.Property in project gocd by gocd.

the class SleepWork method doWork.

@Override
public void doWork(AgentIdentifier agentIdentifier, BuildRepositoryRemote remoteBuildRepository, GoArtifactsManipulator manipulator, EnvironmentVariableContext environmentVariableContext, AgentRuntimeInfo agentRuntimeInfo, PackageRepositoryExtension packageRepositoryExtension, SCMExtension scmExtension, TaskExtension taskExtension) {
    cancelLatch = new CountDownLatch(1);
    agentRuntimeInfo.busy(new AgentBuildingInfo("sleepwork", "sleepwork1"));
    boolean canceled = false;
    DefaultGoPublisher goPublisher = new DefaultGoPublisher(manipulator, new JobIdentifier(), remoteBuildRepository, agentRuntimeInfo);
    try {
        if (this.sleepInMilliSeconds > 0) {
            canceled = cancelLatch.await(this.sleepInMilliSeconds, TimeUnit.MILLISECONDS);
        }
        String result = canceled ? "done_canceled" : "done";
        manipulator.setProperty(null, new Property(name + "_result", result));
        SystemEnvironment systemEnvironment = new SystemEnvironment();
        if (systemEnvironment.isConsoleLogsThroughWebsocketEnabled() && systemEnvironment.isWebsocketsForAgentsEnabled()) {
            goPublisher.consumeLine(format("Sleeping for %s milliseconds", this.sleepInMilliSeconds));
        }
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    }
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) AgentBuildingInfo(com.thoughtworks.go.server.service.AgentBuildingInfo) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) CountDownLatch(java.util.concurrent.CountDownLatch) Property(com.thoughtworks.go.domain.Property)

Aggregations

Property (com.thoughtworks.go.domain.Property)13 Properties (com.thoughtworks.go.domain.Properties)6 Test (org.junit.Test)5 JobIdentifier (com.thoughtworks.go.domain.JobIdentifier)3 Csv (com.thoughtworks.go.util.Csv)3 AgentBuildingInfo (com.thoughtworks.go.server.service.AgentBuildingInfo)2 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)2 File (java.io.File)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 PropertyDao (com.thoughtworks.go.server.dao.PropertyDao)1 CsvRow (com.thoughtworks.go.util.CsvRow)1 ArrayList (java.util.ArrayList)1