├── README.md ├── src └── main │ ├── resources │ ├── index.jelly │ └── org │ │ └── jenkinsci │ │ └── plugins │ │ └── cockpitnotification │ │ └── HudsonNotificationProperty │ │ ├── help-encryptionkey.html │ │ ├── help-teamtoken.html │ │ ├── help-endpoints.html │ │ ├── help-timeout.html │ │ ├── help-url.html │ │ └── config.jelly │ └── java │ └── org │ └── jenkinsci │ └── plugins │ └── cockpitnotification │ ├── JobState.java │ ├── ScmState.java │ ├── Utils.java │ ├── JobListener.java │ ├── HudsonNotificationProperty.java │ ├── HostnamePort.java │ ├── TripleDES.java │ ├── Format.java │ ├── HudsonNotificationPropertyDescriptor.java │ ├── BuildState.java │ ├── Endpoint.java │ ├── Phase.java │ └── Protocol.java ├── pom.xml └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # agile-cockpit-notification-plugin 2 | This plugin can be used by cockpit users to get the Jenkins build information. 3 | -------------------------------------------------------------------------------- /src/main/resources/index.jelly: -------------------------------------------------------------------------------- 1 | 2 |
3 | This plugin sends the notifications about the build informatoin to Agile-Cockpit. 4 |
5 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cockpitnotification/HudsonNotificationProperty/help-encryptionkey.html: -------------------------------------------------------------------------------- 1 |
Please contact support@agilecockpit.com for more information
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cockpitnotification/HudsonNotificationProperty/help-teamtoken.html: -------------------------------------------------------------------------------- 1 |
Mantadatory field. Please contact support@agilecockpit.com for more information
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cockpitnotification/HudsonNotificationProperty/help-endpoints.html: -------------------------------------------------------------------------------- 1 |
Sends notifications about Job status to the defined endpoints 2 | using UDP,TCP or HTTP protocols.
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cockpitnotification/HudsonNotificationProperty/help-timeout.html: -------------------------------------------------------------------------------- 1 |
Sets connection timeout (in milliseconds) for TCP and HTTP. Default timeout is 30 seconds (30,000 ms)
-------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cockpitnotification/HudsonNotificationProperty/help-url.html: -------------------------------------------------------------------------------- 1 |
2 | 8 |
9 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cockpitnotification/JobState.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cockpitnotification; 2 | import com.thoughtworks.xstream.annotations.XStreamAlias; 3 | 4 | /** 5 | * 6 | * @author n.prakasha 7 | */ 8 | @XStreamAlias("job") 9 | public class JobState { 10 | 11 | private String name; 12 | private String url; 13 | private BuildState build; 14 | private String sourcetype = "JENKINS"; 15 | 16 | public String getName() { 17 | return name; 18 | } 19 | public void setName(String name) { 20 | this.name = name; 21 | } 22 | 23 | public String getUrl() { 24 | return url; 25 | } 26 | public void setUrl(String url) { 27 | this.url = url; 28 | } 29 | 30 | public BuildState getBuild() { 31 | return build; 32 | } 33 | public void setBuild(BuildState build) { 34 | this.build = build; 35 | } 36 | 37 | public String getSourceType(){return this.sourcetype;} 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cockpitnotification/ScmState.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cockpitnotification; 2 | /** 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | public class ScmState 16 | { 17 | private String url; 18 | 19 | private String branch; 20 | 21 | private String commit; 22 | 23 | public String getUrl () 24 | { 25 | return url; 26 | } 27 | 28 | public void setUrl ( String url ) 29 | { 30 | this.url = url; 31 | } 32 | 33 | public String getBranch () 34 | { 35 | return branch; 36 | } 37 | 38 | public void setBranch ( String branch ) 39 | { 40 | this.branch = branch; 41 | } 42 | 43 | public String getCommit () 44 | { 45 | return commit; 46 | } 47 | 48 | public void setCommit ( String commit ) 49 | { 50 | this.commit = commit; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cockpitnotification/Utils.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cockpitnotification; 2 | import java.util.Arrays; 3 | 4 | 5 | /** 6 | * Helper utilities 7 | */ 8 | public final class Utils 9 | { 10 | private Utils () 11 | { 12 | } 13 | 14 | 15 | /** 16 | * Determines if any of Strings specified is either null or empty. 17 | */ 18 | @SuppressWarnings( "MethodWithMultipleReturnPoints" ) 19 | public static boolean isEmpty( String ... strings ) 20 | { 21 | if (( strings == null ) || ( strings.length < 1 )) { 22 | return true; 23 | } 24 | 25 | for ( String s : strings ) 26 | { 27 | if (( s == null ) || ( s.trim().length() < 1 )) 28 | { 29 | return true; 30 | } 31 | } 32 | 33 | return false; 34 | } 35 | 36 | 37 | /** 38 | * Verifies neither of Strings specified is null or empty. 39 | * @return first String provided 40 | * @throws java.lang.IllegalArgumentException 41 | */ 42 | @SuppressWarnings( "ReturnOfNull" ) 43 | public static String verifyNotEmpty( String ... strings ) 44 | { 45 | if ( isEmpty( strings )) 46 | { 47 | throw new IllegalArgumentException( String.format( 48 | "Some String arguments are null or empty: %s", Arrays.toString( strings ))); 49 | } 50 | 51 | return strings[ 0 ]; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cockpitnotification/JobListener.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cockpitnotification; 2 | /** 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | import hudson.Extension; 17 | import hudson.model.TaskListener; 18 | import hudson.model.Run; 19 | import hudson.model.listeners.RunListener; 20 | 21 | @Extension 22 | @SuppressWarnings("rawtypes") 23 | public class JobListener extends RunListener { 24 | 25 | public JobListener() { 26 | super(Run.class); 27 | } 28 | 29 | @Override 30 | public void onStarted(Run r, TaskListener listener) { 31 | Phase.STARTED.handle(r, listener); 32 | } 33 | 34 | @Override 35 | public void onCompleted(Run r, TaskListener listener) { 36 | Phase.COMPLETED.handle(r, listener); 37 | } 38 | 39 | @Override 40 | public void onFinalized(Run r) { 41 | Phase.FINALIZED.handle(r, TaskListener.NULL); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cockpitnotification/HudsonNotificationProperty.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cockpitnotification; 2 | /** 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | 17 | import hudson.model.AbstractProject; 18 | import hudson.model.JobProperty; 19 | import org.kohsuke.stapler.DataBoundConstructor; 20 | 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | public class HudsonNotificationProperty extends 25 | JobProperty> { 26 | 27 | public final List endpoints; 28 | 29 | @DataBoundConstructor 30 | public HudsonNotificationProperty(List endpoints) { 31 | this.endpoints = new ArrayList( endpoints ); 32 | } 33 | 34 | public List getEndpoints() { 35 | return endpoints; 36 | } 37 | 38 | @SuppressWarnings( "CastToConcreteClass" ) 39 | @Override 40 | public HudsonNotificationPropertyDescriptor getDescriptor() { 41 | return (HudsonNotificationPropertyDescriptor) super.getDescriptor(); 42 | } 43 | } -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cockpitnotification/HostnamePort.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cockpitnotification; 2 | /** 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | import java.util.Scanner; 17 | import java.util.regex.MatchResult; 18 | 19 | public class HostnamePort { 20 | 21 | public final String hostname; 22 | 23 | public final int port; 24 | 25 | public HostnamePort(String hostname, int port) { 26 | this.hostname = hostname; 27 | this.port = port; 28 | } 29 | 30 | public static HostnamePort parseUrl(String url) { 31 | try { 32 | Scanner scanner = new Scanner(url); 33 | scanner.findInLine("(.+):(\\d{1,5})"); 34 | MatchResult result = scanner.match(); 35 | if (result.groupCount() != 2) { 36 | return null; 37 | } 38 | String hostname = result.group(1); 39 | int port = Integer.valueOf(result.group(2)); 40 | return new HostnamePort(hostname, port); 41 | } catch (Exception e) { 42 | return null; 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cockpitnotification/TripleDES.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cockpitnotification; 2 | 3 | import javax.crypto.Cipher; 4 | import javax.crypto.spec.IvParameterSpec; 5 | import javax.crypto.spec.SecretKeySpec; 6 | 7 | /** 8 | * 9 | * @author n.prakasha 10 | */ 11 | public class TripleDES { 12 | 13 | private static String key; 14 | private static String initializationVector; 15 | 16 | public TripleDES(String encryptionkey,String vectorkey) 17 | { 18 | this.key = encryptionkey; 19 | this.initializationVector = vectorkey; 20 | } 21 | 22 | public static String encryptText(String plainText) throws Exception { 23 | //---- Use specified 3DES key and IV from other source -------------- 24 | byte[] plaintext = plainText.getBytes(); 25 | byte[] tdesKeyData = key.getBytes(); 26 | // byte[] myIV = initializationVector.getBytes(); 27 | Cipher c3des = Cipher.getInstance("DESede/CBC/PKCS5Padding"); 28 | SecretKeySpec myKey = new SecretKeySpec(tdesKeyData, "DESede"); 29 | IvParameterSpec ivspec = new IvParameterSpec(initializationVector.getBytes()); 30 | c3des.init(Cipher.ENCRYPT_MODE, myKey, ivspec); 31 | byte[] cipherText = c3des.doFinal(plaintext); 32 | return new sun.misc.BASE64Encoder().encode(cipherText); 33 | } 34 | 35 | public static String decryptText(String cipherText) throws Exception { 36 | byte[] encData = new sun.misc.BASE64Decoder().decodeBuffer(cipherText); 37 | Cipher decipher = Cipher.getInstance("DESede/CBC/PKCS5Padding"); 38 | byte[] tdesKeyData = key.getBytes(); 39 | SecretKeySpec myKey = new SecretKeySpec(tdesKeyData, "DESede"); 40 | IvParameterSpec ivspec = new IvParameterSpec(initializationVector.getBytes()); 41 | decipher.init(Cipher.DECRYPT_MODE, myKey, ivspec); 42 | byte[] plainText = decipher.doFinal(encData); 43 | return new String(plainText); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cockpitnotification/Format.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cockpitnotification; 2 | 3 | /** 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | import com.google.gson.FieldNamingPolicy; 17 | import com.google.gson.Gson; 18 | import com.google.gson.GsonBuilder; 19 | import com.thoughtworks.xstream.XStream; 20 | 21 | import java.io.IOException; 22 | 23 | public enum Format { 24 | XML { 25 | private final XStream xstream = new XStream(); 26 | 27 | @Override 28 | protected byte[] serialize(JobState jobState, Endpoint target) throws IOException, Throwable { 29 | xstream.processAnnotations(JobState.class); 30 | return xstream.toXML(jobState).getBytes("UTF-8"); 31 | } 32 | }, 33 | JSON { 34 | private final Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create(); 35 | 36 | @Override 37 | protected byte[] serialize(JobState jobState, Endpoint target) throws IOException, Throwable { 38 | String encryptionKey = target.getEncryptionkey(); 39 | String initialVector = target.getVectorkey(); 40 | 41 | String encryptionData = ""; 42 | try { 43 | TripleDES tripleDes = new TripleDES(encryptionKey, initialVector); 44 | encryptionData = tripleDes.encryptText(gson.toJson(jobState)); 45 | } catch (Exception exception) { 46 | throw exception; 47 | } 48 | 49 | return encryptionData.getBytes("UTF-8"); 50 | } 51 | }; 52 | 53 | protected abstract byte[] serialize(JobState jobState, Endpoint target) throws IOException, Throwable; 54 | } 55 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | org.jenkins-ci.plugins 8 | plugin 9 | 10 | 1.580.1 11 | 12 | 13 | org.jenkins-ci.plugins 14 | agile-cockpit-notification 15 | 1.0 16 | hpi 17 | 18 | Agile Cockpit Notification Plugin 19 | This plugin can be used by cockpit users to get the Jenkins build information. 20 | https://wiki.jenkins-ci.org/display/JENKINS/Agile+Cockpit+Notification+Plugin 21 | 22 | 23 | prakashan_prowareness 24 | Prakasha Nagaraju 25 | n.prakasha@prowareness.nl 26 | 27 | 28 | 29 | scm:git:ssh://github.com/jenkinsci/agile-cockpit-notification-plugin.git 30 | scm:git:ssh://git@github.com/jenkinsci/agile-cockpit-notification-plugin.git 31 | https://github.com/jenkinsci/agile-cockpit-notification-plugin.git 32 | 33 | 34 | 35 | repo.jenkins-ci.org 36 | http://repo.jenkins-ci.org/public/ 37 | 38 | 39 | 40 | 41 | repo.jenkins-ci.org 42 | http://repo.jenkins-ci.org/public/ 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | org.apache.maven.plugins 52 | maven-compiler-plugin 53 | 3.5.1 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | com.google.code.gson 63 | gson 64 | 2.2.4 65 | 66 | 67 | 68 | org.jenkins-ci.plugins 69 | s3 70 | 0.6 71 | true 72 | 73 | 74 | 75 | 76 | The Apache Software License, Version 2.0 77 | http://www.apache.org/licenses/LICENSE-2.0.txt 78 | repo 79 | A business-friendly OSS license 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cockpitnotification/HudsonNotificationPropertyDescriptor.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cockpitnotification; 2 | /** 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | import hudson.util.FormValidation; 17 | import hudson.Extension; 18 | import hudson.model.Job; 19 | import hudson.model.JobPropertyDescriptor; 20 | import net.sf.json.JSON; 21 | import net.sf.json.JSONArray; 22 | import net.sf.json.JSONObject; 23 | import org.kohsuke.stapler.QueryParameter; 24 | import org.kohsuke.stapler.StaplerRequest; 25 | 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | 29 | @Extension 30 | public final class HudsonNotificationPropertyDescriptor extends JobPropertyDescriptor { 31 | 32 | public HudsonNotificationPropertyDescriptor() { 33 | super(HudsonNotificationProperty.class); 34 | load(); 35 | } 36 | 37 | private List endpoints = new ArrayList(); 38 | 39 | public boolean isEnabled() { 40 | return !endpoints.isEmpty(); 41 | } 42 | 43 | public List getTargets() { 44 | return endpoints; 45 | } 46 | 47 | public void setEndpoints(List endpoints) { 48 | this.endpoints = new ArrayList( endpoints ); 49 | } 50 | 51 | @Override 52 | public boolean isApplicable(@SuppressWarnings("rawtypes") Class jobType) { 53 | return true; 54 | } 55 | 56 | @Override 57 | public String getDisplayName() { 58 | return "Hudson Job Notification"; 59 | } 60 | 61 | public int getDefaultTimeout(){ 62 | return Endpoint.DEFAULT_TIMEOUT; 63 | } 64 | 65 | @Override 66 | public HudsonNotificationProperty newInstance(StaplerRequest req, JSONObject formData) throws FormException { 67 | 68 | List endpoints = new ArrayList(); 69 | if (formData != null && !formData.isNullObject()) { 70 | JSON endpointsData = (JSON) formData.get("endpoints"); 71 | if (endpointsData != null && !endpointsData.isEmpty()) { 72 | if (endpointsData.isArray()) { 73 | JSONArray endpointsArrayData = (JSONArray) endpointsData; 74 | endpoints.addAll(req.bindJSONToList(Endpoint.class, endpointsArrayData)); 75 | } else { 76 | JSONObject endpointsObjectData = (JSONObject) endpointsData; 77 | endpoints.add(req.bindJSON(Endpoint.class, endpointsObjectData)); 78 | } 79 | } 80 | } 81 | HudsonNotificationProperty notificationProperty = new HudsonNotificationProperty(endpoints); 82 | return notificationProperty; 83 | } 84 | 85 | public FormValidation doCheckUrl(@QueryParameter(value = "url", fixEmpty = true) String url, @QueryParameter(value = "protocol") String protocolParameter) { 86 | Protocol protocol = Protocol.valueOf(protocolParameter); 87 | try { 88 | protocol.validateUrl(url); 89 | return FormValidation.ok(); 90 | } catch (Exception e) { 91 | return FormValidation.error(e.getMessage()); 92 | } 93 | } 94 | 95 | @Override 96 | public boolean configure(StaplerRequest req, JSONObject formData) 97 | { 98 | save(); 99 | return true; 100 | } 101 | 102 | } -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cockpitnotification/BuildState.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cockpitnotification; 2 | 3 | import hudson.model.AbstractBuild; 4 | import hudson.model.Cause; 5 | import hudson.model.Job; 6 | import hudson.model.Run; 7 | import hudson.util.DescribableList; 8 | import jenkins.model.Jenkins; 9 | 10 | import java.io.File; 11 | import java.lang.StringBuilder; 12 | import java.util.Date; 13 | import java.util.HashMap; 14 | import java.util.List; 15 | import java.util.Map; 16 | import static org.jenkinsci.plugins.cockpitnotification.Utils.*; 17 | 18 | /** 19 | * Give the information about the builds 20 | */ 21 | public class BuildState { 22 | 23 | private Phase phase; 24 | private StringBuilder log; 25 | 26 | private String fullUrl; 27 | private int number; 28 | private String status; 29 | private String displayName; 30 | private String jobname; 31 | private String description; 32 | private long duration; 33 | private Date requestedon; 34 | private String userid; 35 | private String shortdescription; 36 | private String username; 37 | 38 | public String getShortDescription() { 39 | return this.shortdescription; 40 | } 41 | 42 | public void setShorttDescription(String shortdescription) { 43 | this.shortdescription = this.shortdescription; 44 | } 45 | 46 | public String getUserId() { 47 | return this.userid; 48 | } 49 | 50 | public void setUserId(String userId) { 51 | this.userid = userId; 52 | } 53 | 54 | public String getUserName() { 55 | return this.username; 56 | } 57 | 58 | public void setUserName(String username) { 59 | this.username = username; 60 | } 61 | 62 | public String getJobName() { 63 | return this.jobname; 64 | } 65 | 66 | public void setJobName(String jobname) { 67 | this.jobname = jobname; 68 | } 69 | 70 | public String getDescription() { 71 | return this.description; 72 | } 73 | 74 | public void setDescription(String description) { 75 | this.description = description; 76 | } 77 | 78 | public long getDuration() { 79 | return this.duration; 80 | } 81 | 82 | public void setDuration(long duration) { 83 | this.duration = duration; 84 | } 85 | 86 | public Date getRequestedOn() { 87 | return this.requestedon; 88 | } 89 | 90 | public void setRequestedOn(Date requestedon) { 91 | this.requestedon = requestedon; 92 | } 93 | 94 | public int getNumber() { 95 | return number; 96 | } 97 | 98 | public void setNumber(int number) { 99 | this.number = number; 100 | } 101 | 102 | public Phase getPhase() { 103 | return phase; 104 | } 105 | 106 | public void setPhase(Phase phase) { 107 | this.phase = phase; 108 | } 109 | 110 | public String getStatus() { 111 | return status; 112 | } 113 | 114 | public void setStatus(String status) { 115 | this.status = status; 116 | } 117 | 118 | public void setDisplayName(String displayName) { 119 | this.displayName = displayName; 120 | } 121 | 122 | public String getDisplayName() { 123 | return displayName; 124 | } 125 | 126 | public StringBuilder getLog() { 127 | return this.log; 128 | } 129 | 130 | public void setLog(StringBuilder log) { 131 | this.log = log; 132 | } 133 | 134 | public void setBuildCauses(Cause.UserIdCause cause) { 135 | this.shortdescription = cause.getShortDescription(); 136 | this.userid = cause.getUserId(); 137 | this.username = cause.getUserName(); 138 | } 139 | 140 | public void setBuildCausedAutomatically(String shortDescription) 141 | { 142 | this.userid = ""; 143 | this.username = shortDescription; 144 | this.shortdescription = shortDescription + ". This build was automatically triggered."; 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cockpitnotification/Endpoint.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cockpitnotification; 2 | /** 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | import hudson.util.FormValidation; 17 | import org.kohsuke.stapler.DataBoundConstructor; 18 | import org.kohsuke.stapler.QueryParameter; 19 | 20 | 21 | public class Endpoint { 22 | 23 | public static final Integer DEFAULT_TIMEOUT = 30000; 24 | 25 | //public static final String DEFAULT_TEAM_TOKEN = "52026B18-ADF4-4073-AF49-ABF6A72D4272"; 26 | 27 | private Protocol protocol; 28 | 29 | private Format format = Format.JSON; 30 | 31 | private String url; 32 | 33 | private String event = "all"; 34 | 35 | private Integer timeout = DEFAULT_TIMEOUT; 36 | 37 | private Integer loglines = 0; 38 | 39 | private String teamtoken; 40 | 41 | private String encryptionkey; 42 | 43 | private String vectorkey; 44 | 45 | private String username; 46 | 47 | private String password; 48 | 49 | @DataBoundConstructor 50 | public Endpoint(Protocol protocol, String url,String event, 51 | Format format, Integer timeout, Integer loglines, String teamtoken,String encryptionkey,String vectorkey) 52 | { 53 | setProtocol( protocol ); 54 | setUrl( url ); 55 | setEvent( event ); 56 | setFormat( format ); 57 | setTimeout( timeout ); 58 | setLoglines( loglines ); 59 | setTeamtoken(teamtoken); 60 | setEncryptionkey(encryptionkey); 61 | setVectorkey(vectorkey); 62 | } 63 | 64 | 65 | public void setTeamtoken(String teamtoken) 66 | { 67 | this.teamtoken = teamtoken; 68 | } 69 | 70 | public String getTeamtoken() 71 | { 72 | return this.teamtoken; 73 | } 74 | 75 | public void setEncryptionkey(String encryptionkey) 76 | { 77 | this.encryptionkey = encryptionkey; 78 | } 79 | 80 | public String getEncryptionkey() 81 | { 82 | return this.encryptionkey; 83 | } 84 | 85 | public void setVectorkey(String vectorkey) 86 | { 87 | this.vectorkey = vectorkey; 88 | } 89 | 90 | public String getVectorkey() 91 | { 92 | return this.vectorkey; 93 | } 94 | 95 | public int getTimeout() { 96 | return timeout == null ? DEFAULT_TIMEOUT : timeout; 97 | } 98 | 99 | public void setTimeout(Integer timeout) { 100 | this.timeout = timeout; 101 | } 102 | 103 | public Protocol getProtocol() { 104 | return protocol; 105 | } 106 | 107 | public void setProtocol(Protocol protocol) { 108 | this.protocol = protocol; 109 | } 110 | 111 | public String getUrl() { 112 | return url; 113 | } 114 | 115 | public void setUrl(String url) { 116 | this.url = url; 117 | } 118 | 119 | public String getEvent (){ 120 | return event; 121 | } 122 | 123 | public void setEvent ( String event ){ 124 | this.event = event; 125 | } 126 | 127 | public Format getFormat() { 128 | if (this.format==null){ 129 | this.format = Format.JSON; 130 | } 131 | return format; 132 | } 133 | 134 | public void setFormat(Format format) { 135 | this.format = format; 136 | } 137 | 138 | public Integer getLoglines() { 139 | return this.loglines; 140 | } 141 | 142 | public void setLoglines(Integer loglines) { 143 | this.loglines = loglines; 144 | } 145 | 146 | public FormValidation doCheckURL(@QueryParameter(value = "url", fixEmpty = true) String url) { 147 | if (url.equals("111")) 148 | return FormValidation.ok(); 149 | else 150 | return FormValidation.error("There's a problem here"); 151 | } 152 | 153 | public boolean isJson() { 154 | return getFormat() == Format.JSON; 155 | } 156 | 157 | @Override 158 | public String toString() { 159 | return protocol+":"+url; 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /src/main/resources/org/jenkinsci/plugins/cockpitnotification/HudsonNotificationProperty/config.jelly: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 17 | 18 | 19 | 26 | 27 | 28 | 35 | 36 | 37 | 42 | 43 | 44 | 49 | 50 | 51 | 57 | 58 | 59 | 64 | 65 | 66 | 71 | 72 | 73 | 78 | 79 |
11 | 12 | 15 | 16 |
20 | 21 | 24 | 25 |
29 | 30 | 33 | 34 |
38 | 39 | 40 | 41 |
45 | 46 | 47 | 48 |
52 | 54 | 55 | 56 |
60 | 61 | 62 | 63 |
67 | 68 | 69 | 70 |
74 | 75 | 76 | 77 |
80 |
81 | 82 | 83 | 84 | 85 |
86 |
87 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cockpitnotification/Phase.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cockpitnotification; 2 | 3 | /** 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | import hudson.EnvVars; 17 | import hudson.model.*; 18 | import jenkins.model.Jenkins; 19 | import java.io.IOException; 20 | import java.util.List; 21 | 22 | @SuppressWarnings({"unchecked", "rawtypes"}) 23 | public enum Phase { 24 | STARTED, COMPLETED, FINALIZED; 25 | 26 | @SuppressWarnings("CastToConcreteClass") 27 | public void handle(Run run, TaskListener listener) { 28 | 29 | HudsonNotificationProperty property = (HudsonNotificationProperty) run.getParent().getProperty(HudsonNotificationProperty.class); 30 | if (property == null) { 31 | return; 32 | } 33 | 34 | for (Endpoint target : property.getEndpoints()) { 35 | if (isRun(target)) { 36 | listener.getLogger().println(String.format("Notifying endpoint '%s'", target)); 37 | 38 | try { 39 | JobState jobState = buildJobState(run.getParent(), run, listener, target); 40 | EnvVars environment = run.getEnvironment(listener); 41 | String expandedUrl = environment.expand(target.getUrl()); 42 | target.getProtocol().send(expandedUrl, 43 | target.getFormat().serialize(jobState,target), 44 | target.getTimeout(), 45 | target.isJson(), 46 | target.getTeamtoken(), 47 | target.getEncryptionkey(), 48 | target.getVectorkey()); 49 | 50 | } catch (Throwable error) { 51 | error.printStackTrace(listener.error(String.format("Failed to notify endpoint '%s'", target))); 52 | listener.getLogger().println(String.format("Failed to notify endpoint '%s' - %s: %s", 53 | target, error.getClass().getName(), error.getMessage())); 54 | } 55 | } 56 | } 57 | } 58 | 59 | /** 60 | * Determines if the endpoint specified should be notified at the current 61 | * job phase. 62 | */ 63 | private boolean isRun(Endpoint endpoint) { 64 | String event = endpoint.getEvent(); 65 | return ((event == null) || event.equals("all") || event.equals(this.toString().toLowerCase())); 66 | } 67 | 68 | private JobState buildJobState(Job job, Run run, TaskListener listener, Endpoint target) 69 | throws IOException, InterruptedException { 70 | Jenkins jenkins = Jenkins.getInstance(); 71 | String rootUrl = jenkins.getRootUrl(); 72 | JobState jobState = new JobState(); 73 | BuildState buildState = new BuildState(); 74 | ScmState scmState = new ScmState(); 75 | Result result = run.getResult(); 76 | ParametersAction paramsAction = run.getAction(ParametersAction.class); 77 | EnvVars environment = run.getEnvironment(listener); 78 | StringBuilder log = this.getLog(run, target); 79 | 80 | jobState.setName(job.getName()); 81 | jobState.setUrl(job.getUrl()); 82 | jobState.setBuild(buildState); 83 | 84 | Cause.UserIdCause userIdCause = (Cause.UserIdCause) run.getCause(Cause.UserIdCause.class); 85 | if (userIdCause != null) { 86 | buildState.setBuildCauses(userIdCause); 87 | } else { 88 | List causeList = run.getCauses(); 89 | if (causeList != null) 90 | { 91 | for (int i = 0; i < causeList.size(); i++) 92 | { 93 | Cause actualCause = causeList.get(i); 94 | if(actualCause!=null && actualCause.getShortDescription()!="") 95 | { 96 | buildState.setBuildCausedAutomatically(actualCause.getShortDescription()); 97 | break; 98 | } 99 | } 100 | } 101 | } 102 | 103 | buildState.setDescription(run.getDescription()); 104 | buildState.setDuration(run.getDuration()); 105 | buildState.setRequestedOn(run.getTime()); 106 | buildState.setNumber(run.number); 107 | buildState.setPhase(this); 108 | buildState.setLog(log); 109 | 110 | if (result != null) { 111 | buildState.setStatus(result.toString()); 112 | } 113 | 114 | return jobState; 115 | } 116 | 117 | private StringBuilder getLog(Run run, Endpoint target) { 118 | StringBuilder log = new StringBuilder(""); 119 | Integer loglines = target.getLoglines(); 120 | 121 | if (null == loglines) { 122 | return log; 123 | } 124 | 125 | try { 126 | switch (loglines) { 127 | // The full log 128 | case -1: 129 | log.append(run.getLog()); 130 | break; 131 | default: 132 | List logEntries = run.getLog(loglines); 133 | for (String entry : logEntries) { 134 | log.append(entry); 135 | log.append("\n"); 136 | } 137 | } 138 | } catch (IOException e) { 139 | log.append("Unable to retrieve log"); 140 | } 141 | return log; 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/main/java/org/jenkinsci/plugins/cockpitnotification/Protocol.java: -------------------------------------------------------------------------------- 1 | package org.jenkinsci.plugins.cockpitnotification; 2 | 3 | /** 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | import com.google.gson.FieldNamingPolicy; 17 | import com.google.gson.Gson; 18 | import com.google.gson.GsonBuilder; 19 | import java.io.IOException; 20 | import java.io.OutputStream; 21 | import java.net.DatagramPacket; 22 | import java.net.DatagramSocket; 23 | import java.net.HttpURLConnection; 24 | import java.net.InetAddress; 25 | import java.net.InetSocketAddress; 26 | import java.net.MalformedURLException; 27 | import java.net.Proxy; 28 | import java.net.Socket; 29 | import java.net.SocketAddress; 30 | import java.net.URL; 31 | import static org.jenkinsci.plugins.cockpitnotification.Utils.*; 32 | 33 | import javax.xml.bind.DatatypeConverter; 34 | 35 | public enum Protocol { 36 | 37 | UDP { 38 | @Override 39 | protected void send(String url, byte[] data, int timeout, boolean isJson, String teamtoken,String encryptionkey,String vectorkey) throws IOException { 40 | HostnamePort hostnamePort = HostnamePort.parseUrl(url); 41 | DatagramSocket socket = new DatagramSocket(); 42 | DatagramPacket packet = new DatagramPacket(data, data.length, InetAddress.getByName(hostnamePort.hostname), hostnamePort.port); 43 | socket.send(packet); 44 | } 45 | }, 46 | TCP { 47 | @Override 48 | protected void send(String url, byte[] data, int timeout, boolean isJson, String teamtoken,String encryptionkey,String vectorkey) throws IOException { 49 | HostnamePort hostnamePort = HostnamePort.parseUrl(url); 50 | SocketAddress endpoint = new InetSocketAddress(InetAddress.getByName(hostnamePort.hostname), hostnamePort.port); 51 | Socket socket = new Socket(); 52 | socket.setSoTimeout(timeout); 53 | socket.connect(endpoint, timeout); 54 | OutputStream output = socket.getOutputStream(); 55 | output.write(data); 56 | output.flush(); 57 | output.close(); 58 | } 59 | }, 60 | HTTP { 61 | @Override 62 | protected void send(String url, byte[] data, int timeout, boolean isJson, String teamtoken,String encryptionkey,String vectorkey) throws IOException { 63 | URL targetUrl = new URL(url); 64 | if (!targetUrl.getProtocol().startsWith("http")) { 65 | throw new IllegalArgumentException("Not an http(s) url: " + url); 66 | } 67 | 68 | // Verifying if the HTTP_PROXY is available 69 | final String httpProxyUrl = System.getenv().get("http_proxy"); 70 | URL proxyUrl = null; 71 | if (httpProxyUrl != null && httpProxyUrl.length() > 0) { 72 | proxyUrl = new URL(httpProxyUrl); 73 | if (!proxyUrl.getProtocol().startsWith("http")) { 74 | throw new IllegalArgumentException("Not an http(s) url: " + httpProxyUrl); 75 | } 76 | } 77 | 78 | HttpURLConnection connection = null; 79 | if (proxyUrl == null) { 80 | connection = (HttpURLConnection) targetUrl.openConnection(); 81 | 82 | } else { 83 | // Proxy connection to the address provided 84 | final int proxyPort = proxyUrl.getPort() > 0 ? proxyUrl.getPort() : 80; 85 | Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyUrl.getHost(), proxyPort)); 86 | connection = (HttpURLConnection) targetUrl.openConnection(proxy); 87 | } 88 | 89 | //connection.setRequestProperty("Content-Type", String.format("application/%s;charset=UTF-8", isJson ? "json" : "xml")); 90 | 91 | connection.setRequestProperty("Content-Type", "text/plain;charset=UTF-8"); 92 | connection.setRequestProperty("Authorization", "Basic " + teamtoken); 93 | 94 | connection.setFixedLengthStreamingMode(data.length); 95 | connection.setDoInput(true); 96 | connection.setDoOutput(true); 97 | connection.setConnectTimeout(timeout); 98 | connection.setReadTimeout(timeout); 99 | connection.connect(); 100 | try { 101 | OutputStream output = connection.getOutputStream(); 102 | try { 103 | output.write(data); 104 | output.flush(); 105 | } finally { 106 | output.close(); 107 | } 108 | } finally { 109 | // Follow an HTTP Temporary Redirect if we get one, 110 | // 111 | // NB: Normally using the HttpURLConnection interface, we'd call 112 | // connection.setInstanceFollowRedirects(true) to enable 307 redirect following but 113 | // since we have the connection in streaming mode this does not work and we instead 114 | // re-direct manually. 115 | if (307 == connection.getResponseCode()) { 116 | String location = connection.getHeaderField("Location"); 117 | connection.disconnect(); 118 | send(location, data, timeout, isJson, teamtoken,encryptionkey,vectorkey); 119 | } else { 120 | connection.disconnect(); 121 | } 122 | } 123 | } 124 | 125 | @Override 126 | public void validateUrl(String url) { 127 | try { 128 | // noinspection ResultOfObjectAllocationIgnored 129 | new URL(url); 130 | } catch (MalformedURLException e) { 131 | throw new RuntimeException(String.format("%sUse http://hostname:port/path for endpoint URL", 132 | isEmpty(url) ? "" : "Invalid URL '" + url + "'. ")); 133 | } 134 | } 135 | }; 136 | 137 | protected abstract void send(String url, byte[] data, int timeout, boolean isJson, String teamtoken,String encryptionkey,String vectorkey) throws IOException; 138 | 139 | public void validateUrl(String url) { 140 | try { 141 | HostnamePort hnp = HostnamePort.parseUrl(url); 142 | if (hnp == null) { 143 | throw new Exception(); 144 | } 145 | } catch (Exception e) { 146 | throw new RuntimeException(String.format("%sUse hostname:port for endpoint URL", 147 | isEmpty(url) ? "" : "Invalid URL '" + url + "'. ")); 148 | } 149 | } 150 | 151 | private static boolean isEmpty(String s) { 152 | return ((s == null) || (s.trim().length() < 1)); 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------