Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
[FIXED JENKINS-28769] Merging #234.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Nov 5, 2015
2 parents fd3a15b + 632c164 commit 8cd6449
Show file tree
Hide file tree
Showing 9 changed files with 631 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -13,3 +13,7 @@ out
.settings

demo/snapshot/plugins/

node
node_modules
generates-adjuncts
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -4,6 +4,7 @@ Only noting significant user changes, not internal code cleanups and minor bug f

## 1.11 (upcoming)

* [JENKINS-28769](https://issues.jenkins-ci.org/browse/JENKINS-28769): syntax highlighting, example scripts, and basic code snippets for Workflow scripts in the browser.
* When running the `build` step, the upstream log should now show a link to the downstream build.

## 1.11-beta-2 (Oct 26 2015)
Expand Down
12 changes: 12 additions & 0 deletions cps/gulpfile.js
@@ -0,0 +1,12 @@
//
// See https://github.com/tfennelly/jenkins-js-builder
//
var builder = require('jenkins-js-builder');

//
// Bundle the modules.
// See https://github.com/tfennelly/jenkins-js-builder#bundling
//
builder.bundle('src/main/js/workflow-editor.js')
.withExternalModuleMapping('jquery-detached', 'jquery-detached:jquery2')
.inDir('target/generated-adjuncts/org/jenkinsci/plugins/workflow/cps');
17 changes: 17 additions & 0 deletions cps/package.json
@@ -0,0 +1,17 @@
{
"name": "workflow-ui",
"version": "1.0.0",
"description": "Jenkins Workflow UI",
"author": "Tom Fennelly <tom.fennelly@gmail.com> (https://github.com/tfennelly)",
"license": "MIT",
"devDependencies": {
"gulp": "^3.9.0",
"jenkins-js-builder": "0.0.26",
"jenkins-js-test": "0.0.15"
},
"dependencies": {
"jenkins-js-modules": "1.3.0",
"jquery-detached": "^2.1.4-v2",
"window-handle": "0.0.6"
}
}
250 changes: 250 additions & 0 deletions cps/pom.xml
Expand Up @@ -77,13 +77,35 @@
<artifactId>groovy-cps</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.ui</groupId>
<artifactId>jquery-detached</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.ui</groupId>
<artifactId>ace-editor</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<!-- TODO currently job depends on tests from here; this dependency should probably be broken -->
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>target/generated-adjuncts</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<!--
TODO currently job depends on tests from here; this dependency should probably be broken.
TODO Update the above TODO to make it clear what it's talking about. By "job", I think it is referring to the "workflow-job" module.
-->
<execution>
<goals>
<goal>test-jar</goal>
Expand All @@ -93,4 +115,232 @@
</plugin>
</plugins>
</build>
<!--
Everything from here on is copied from https://github.com/tfennelly/jenkins-js-builder#maven-integration
This would all go into one of the parent pom.xml files, from where every plugin could use it.
-->
<properties>
<node.version>4.0.0</node.version>
<npm.version>2.13.1</npm.version>
</properties>
<profiles>
<!--
Manually download node and NPM for the frontend plugin so it gets cached in the local maven repo.
Otherwise frontend will be downloading it all the time. The download-maven-plugin
caches it's downloads.
-->
<profile>
<id>node-classifier-linux</id>
<activation>
<os><family>Linux</family><arch>amd64</arch></os>
</activation>
<properties>
<node.download.file>node-v${node.version}-linux-x64.tar.gz</node.download.file>
<node.download.classifier></node.download.classifier>
</properties>
</profile>
<profile>
<id>node-classifier-mac</id>
<activation>
<os><family>mac</family></os>
</activation>
<properties>
<node.download.file>node-v${node.version}-darwin-x64.tar.gz</node.download.file>
<node.download.classifier></node.download.classifier>
</properties>
</profile>
<profile>
<id>node-classifier-windows</id>
<activation>
<os><family>windows</family><arch>x64</arch></os>
</activation>
<properties>
<node.download.file>win-x64/node.exe</node.download.file>
<node.download.classifier>/x64</node.download.classifier>
</properties>
</profile>
<profile>
<id>node-classifier-windows-amd64</id>
<activation>
<os><family>windows</family><arch>amd64</arch></os>
</activation>
<properties>
<node.download.file>win-x64/node.exe</node.download.file>
<node.download.classifier>/x64</node.download.classifier>
</properties>
</profile>
<profile>
<id>node-classifier-windows-x86</id>
<activation>
<os><family>windows</family><arch>x86</arch></os>
</activation>
<properties>
<node.download.file>win-x86/node.exe</node.download.file>
<node.download.classifier></node.download.classifier>
</properties>
</profile>
<profile>
<id>node-download</id>
<activation>
<file>
<exists>package.json</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>get-node</id>
<phase>initialize</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://nodejs.org/dist/v${node.version}/${node.download.file}</url>
<unpack>false</unpack>
<outputDirectory>${project.build.directory}/frontend/v${node.version}${node.download.classifier}</outputDirectory>
</configuration>
</execution>
<execution>
<id>get-npm</id>
<phase>initialize</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>http://registry.npmjs.org/npm/-/npm-${npm.version}.tgz</url>
<unpack>false</unpack>
<outputDirectory>${project.build.directory}/frontend/</outputDirectory>
<outputFileName>npm-${npm.version}.tgz</outputFileName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>gulp-execution</id>
<activation>
<file>
<exists>gulpfile.js</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.3.1</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>3.1.0</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>0.0.23</version>

<executions>

<execution>
<phase>initialize</phase>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v${node.version}</nodeVersion>
<npmVersion>${npm.version}</npmVersion>
<!-- Use the pre-download node and npm packages. See download-maven-plugin config above. -->
<downloadRoot>${project.baseUri}target/frontend/</downloadRoot>
</configuration>
</execution>

<execution>
<phase>initialize</phase>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<!-- Note that this may not be omitted lest maven-release-plugin be confused (frontend-maven-plugin #109): -->
<arguments>install</arguments>
</configuration>
</execution>

<execution>
<phase>generate-sources</phase>
<id>gulp bundle</id>
<goals>
<goal>gulp</goal>
</goals>
<configuration>
<arguments>bundle</arguments>
</configuration>
</execution>

<execution>
<phase>test</phase>
<id>gulp test</id>
<goals>
<goal>gulp</goal>
</goals>
</execution>

</executions>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>clean-node</id>
<activation>
<file>
<exists>package.json</exists>
</file>
<property>
<name>cleanNode</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>node</directory>
<followSymlinks>false</followSymlinks>
</fileset>
<fileset>
<directory>node_modules</directory>
<followSymlinks>false</followSymlinks>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>
</profile>

</profiles>
</project>
70 changes: 70 additions & 0 deletions cps/src/main/js/samples.js
@@ -0,0 +1,70 @@
var samples = [];

exports.addSamplesWidget = function(editor) {
var $ = require('jquery-detached').getJQuery();
var $aceEditor = $('#workflow-editor');
var sampleSelect = $('<select></select>');

sampleSelect.append('<option >try sample workflow...</option>');
for (var i = 0; i < samples.length; i++) {
sampleSelect.append('<option value="' + samples[i].name + '">' + samples[i].title + '</option>');
}

var samplesDiv = $('<div class="samples"></div>');
samplesDiv.append(sampleSelect);

samplesDiv.insertBefore($aceEditor);
samplesDiv.css({
'position': 'absolute',
'right': '1px',
'z-index': 100,
'top': '1px'
});

sampleSelect.change(function() {
var theSample = getSample(sampleSelect.val());
editor.setValue(theSample, 1);
});
};

function getSample(sampleName) {
for (var i = 0; i < samples.length; i++) {
if (samples[i].name === sampleName) {
return samples[i].script;
}
}
return '';
}

samples.push({
name: 'hello',
title: 'Hello World',
script: "node {\n" +
" stage 'Stage 1'\n" +
" echo 'Hello World 1'\n" +
" stage 'Stage 2'\n" +
" echo 'Hello World 2'\n" +
"}"
});

samples.push({
name: 'github-maven',
title: 'GitHub + Maven',
script: "node {\n" +
" // Mark the code checkout 'stage'....\n" +
" stage 'Checkout'\n" +
"\n" +
" // Get some code from a GitHub repository\n" +
" git url: 'https://github.com/jglick/simple-maven-project-with-tests.git'\n" +
"\n" +
" // Get the maven tool.\n" +
" // ** NOTE: This 'M3' maven tool must be configured\n" +
" // ** in the global configuration. \n" +
" def mvnHome = tool 'M3'\n" +
"\n" +
" // Mark the code build 'stage'....\n" +
" stage 'Build'\n" +
" // Run the maven build\n" +
" sh \"${mvnHome}/bin/mvn clean install\"\n" +
"}"
});

0 comments on commit 8cd6449

Please sign in to comment.