Skip to content

Commit

Permalink
Merge pull request #1 from jenkinsci/referenceImpl
Browse files Browse the repository at this point in the history
External Logging API Implementation. v1
  • Loading branch information
oleg-nenashev committed Aug 3, 2018
2 parents cea321f + 32dc947 commit 1b3a23e
Show file tree
Hide file tree
Showing 40 changed files with 1,862 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
target

# mvn hpi:run
work

# IntelliJ IDEA project files
*.iml
*.iws
*.ipr
.idea

# Eclipse project files
.settings
.classpath
.project
7 changes: 7 additions & 0 deletions .mvn/extensions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">
<extension>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>git-changelist-maven-extension</artifactId>
<version>1.0-beta-3</version>
</extension>
</extensions>
2 changes: 2 additions & 0 deletions .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-Pconsume-incrementals
-Pmight-produce-incrementals
1 change: 1 addition & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
buildPlugin(platforms: ['linux'])
126 changes: 126 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>3.18</version>
<relativePath />
</parent>

<groupId>io.jenkins.plugins.external-logging</groupId>
<artifactId>external-logging-api</artifactId>
<name>External Logging API plugin</name>
<description>The plugin provides API to simplify external logging implementations for Jenkins</description>
<url>https://wiki.jenkins.io/display/JENKINS/External+Logging+API+Plugin</url>
<version>${revision}${changelist}</version>
<packaging>hpi</packaging>

<properties>
<revision>1.0-alpha-1</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.135-rc15088.42aa6febbbed</jenkins.version>
<java.level>8</java.level>
<useBeta>true</useBeta>
</properties>

<licenses>
<license>
<name>MIT License</name>
<url>https://opensource.org/licenses/MIT</url>
</license>
</licenses>

<scm>
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
<tag>${scmTag}</tag>
</scm>

<dependencies>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>unique-id</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>mask-passwords</artifactId>
<version>2.12.0</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>2.22-rc311.5616213fbed0</version> <!-- TODO https://github.com/jenkinsci/workflow-job-plugin/pull/27 -->
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<version>2.19-rc265.3e5e4aeecfff</version> <!-- TODO https://github.com/jenkinsci/workflow-support-plugin/pull/15 -->
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>2.29-rc219.239019e84015</version> <!-- TODO https://github.com/jenkinsci/workflow-api-plugin/pull/17 -->
</dependency>

<!-- For testing of Log wrapping in Pipeline -->
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>2.20-rc333.74dc7c303e6d</version> <!-- TODO https://github.com/jenkinsci/workflow-durable-task-step-plugin/pull/21 -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>2.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.15</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>scm-api</artifactId>
<version>2.2.6</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
<version>1.39</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>credentials-binding</artifactId>
<version>1.15</version>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

</project>
54 changes: 54 additions & 0 deletions src/main/java/io/jenkins/plugins/extlogging/api/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.jenkins.plugins.extlogging.api;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
* Stores events which can be sent over the channel.
* @author Oleg Nenashev
* @since TODO
*/
public class Event {

final String message;
final long timestamp;
final long id;

Map<String, Serializable> data = new HashMap<>();

public Event(long id, String message, long timestamp) {
this.id = id;
this.message = message;
this.timestamp = timestamp;
}

public long getId() {
return id;
}

public String getMessage() {
return message;
}

public long getTimestamp() {
return timestamp;
}

public Map<String, Serializable> getData() {
return data;
}

@Override
public String toString() {
return String.format("[%d] - %s", timestamp, message);
}

public void setData(Map<String, Serializable> data) {
this.data = data;
}

public String toStringWithData() {
return String.format("[%d] - %s: %s", timestamp, message, data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.jenkins.plugins.extlogging.api;

import jenkins.model.logging.LogBrowser;
import jenkins.model.logging.Loggable;

import javax.annotation.Nonnull;

/**
* Base abstract class for External Log Browsers.
* @author Oleg Nenashev
* @since TODO
*/
public abstract class ExternalLogBrowser extends LogBrowser {

public ExternalLogBrowser(@Nonnull Loggable loggable) {
super(loggable);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.jenkins.plugins.extlogging.api;

import hudson.ExtensionPoint;
import hudson.model.Describable;
import hudson.model.Descriptor;
import jenkins.model.Jenkins;
import jenkins.model.logging.LogBrowser;
import jenkins.model.logging.Loggable;

import javax.annotation.CheckForNull;

/**
* @author Oleg Nenashev
* @since TODO
*/
public abstract class ExternalLogBrowserFactory
implements Describable<ExternalLogBrowserFactory>, ExtensionPoint {

@CheckForNull
public abstract LogBrowser create(Loggable loggable);

@Override
public Descriptor<ExternalLogBrowserFactory> getDescriptor() {
return Jenkins.get().getDescriptor(getClass());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.jenkins.plugins.extlogging.api;

import hudson.model.Descriptor;

/**
* Descriptor for {@link ExternalLogBrowserFactory}
* @author Oleg Nenashev
* @since TODO
*/
public class ExternalLogBrowserFactoryDescriptor
extends Descriptor<ExternalLogBrowserFactory> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.jenkins.plugins.extlogging.api;

import java.io.IOException;
import java.io.Serializable;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;

/**
* Implements logging of events
* @author Oleg Nenashev
* @since TODO
*/
public abstract class ExternalLoggingEventWriter extends Writer implements Serializable {

Map<String, Serializable> metadata = new HashMap<>();
AtomicLong messageCounter = new AtomicLong();

public abstract void writeEvent(Event event) throws IOException;

public void writeMessage(String message) throws IOException {
Event event = new Event(messageCounter.getAndIncrement(), message, System.currentTimeMillis());
event.setData(metadata); // We do not copy the entry to save performance, custom implementations may need better logic
writeEvent(event);
}

public void addMetadataEntry(String key, Serializable value) {
metadata.put(key, value);
}

@Override
public void write(char[] cbuf, int off, int len) throws IOException {
String message = new String(cbuf, off, len);
writeMessage(message);
}

@Override
public void close() throws IOException {
// noop
}

@Override
public void flush() throws IOException {
// noop
}
}
Loading

0 comments on commit 1b3a23e

Please sign in to comment.