Skip to content

Commit

Permalink
Fixed JENKINS-9785 : option to run maven in headless mode to avoid bo…
Browse files Browse the repository at this point in the history
…ring dock icon to jump and take the focus on OSX
  • Loading branch information
ndeloof committed May 31, 2011
1 parent 6204016 commit a84188e
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 13 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -68,6 +68,9 @@
<li class=rfe>
Post-build deploy task for Maven jobs : Repositories definitions can now be read from the POMs.
(<a href="http://issues.jenkins-ci.org/browse/JENKINS-9786">issue 9786</a>)
<li class=rfe>
Run maven jobs as headless process. on OSX this avoid jumping Dock icon to take focus.
(<a href="http://issues.jenkins-ci.org/browse/JENKINS-9785">issue 9785</a>)
</ul>
</div><!--=TRUNK-END=-->

Expand Down
@@ -1,10 +1,12 @@
package hudson.maven;

import static hudson.Util.fixNull;

import hudson.AbortException;
import hudson.EnvVars;
import hudson.FilePath;
import hudson.Launcher;
import hudson.Platform;
import hudson.Proc;
import hudson.maven.ProcessCache.NewProcess;
import hudson.model.BuildListener;
Expand All @@ -24,7 +26,6 @@
import hudson.tasks.Maven.MavenInstallation;
import hudson.tasks._maven.MavenConsoleAnnotator;
import hudson.util.ArgumentListBuilder;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
Expand All @@ -37,8 +38,6 @@
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.util.Arrays;

import org.jenkinsci.plugins.tokenmacro.TokenMacro;
import org.kohsuke.stapler.framework.io.IOException2;

/*
Expand Down Expand Up @@ -274,7 +273,19 @@ public String getMavenOpts() {

}
}


if (mms.runHeadless()) {
// Configure headless process
mavenOpts += " -Djava.awt.headless=true";
} else {
if (Platform.isDarwin()) {
// Would be cool to replace the generic Java icon with jenkins logo, but requires
// the file absolute path to be available on slave *before* the process run on it :-/
// Maybe we could enforce this from the DMG installer on OSX
// TODO mavenOpts += " -Xdock:name=Jenkins -Xdock:icon=jenkins.png";
}
}

return envVars.expand(mavenOpts);
}

Expand Down
15 changes: 15 additions & 0 deletions maven-plugin/src/main/java/hudson/maven/MavenModuleSet.java
Expand Up @@ -204,6 +204,12 @@ public final class MavenModuleSet extends AbstractMavenProject<MavenModuleSet,Ma
*/
private int mavenValidationLevel = -1;

/**
* Inform jenkins this build don't use UI code and can run without access to graphical environment. Could be used
* later to select a headless-slave from a pool, but first introduced for JENKINS-9785
*/
private boolean runHeadless = false;

/**
* Reporters configured at {@link MavenModuleSet} level. Applies to all {@link MavenModule} builds.
*/
Expand Down Expand Up @@ -357,6 +363,10 @@ public boolean ignoreUpstremChanges() {
return ignoreUpstremChanges;
}

public boolean runHeadless() {
return runHeadless;
}

public boolean isArchivingDisabled() {
return archivingDisabled;
}
Expand All @@ -377,6 +387,10 @@ public void setIgnoreUpstremChanges(boolean ignoreUpstremChanges) {
this.ignoreUpstremChanges = ignoreUpstremChanges;
}

public void setRunHeadless(boolean runHeadless) {
this.runHeadless = runHeadless;
}

public void setIsArchivingDisabled(boolean archivingDisabled) {
this.archivingDisabled = archivingDisabled;
}
Expand Down Expand Up @@ -811,6 +825,7 @@ protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOExceptio
aggregatorStyleBuild = !req.hasParameter("maven.perModuleBuild");
usePrivateRepository = req.hasParameter("maven.usePrivateRepository");
ignoreUpstremChanges = !json.has("triggerByDependency");
runHeadless = req.hasParameter("maven.runHeadless");
incrementalBuild = req.hasParameter("maven.incrementalBuild");
archivingDisabled = req.hasParameter("maven.archivingDisabled");
resolveDependencies = req.hasParameter( "maven.resolveDependencies" );
Expand Down
Expand Up @@ -91,7 +91,9 @@ THE SOFTWARE.
checked="${it.usesPrivateRepository()}" />
<f:optionalBlock name="maven.resolveDependencies" title="${%Resolve Dependencies during Pom parsing}"
checked="${it.isResolveDependencies()}" />
<f:optionalBlock name="maven.processPlugins" title="${%Process Plugins during Pom parsing}"
<f:optionalBlock name="maven.runHeadless" title="${%Run Headless}" help="/plugin/maven-plugin/run-headless.html"
checked="${it.runHeadless()}" />
<f:optionalBlock name="maven.processPlugins" title="${%Process Plugins during Pom parsing}"
checked="${it.isProcessPlugins()}" />
<p:config-customWorkspace />

Expand Down
Expand Up @@ -21,16 +21,22 @@
# THE SOFTWARE.

Alternate\ settings\ file=Fichier settings alternatif
Block\ build\ when\ dependency\ building=Bloquer le build pendant la construction des d\u00E9pendances
Block\ build\ when\ dependency\ building=Bloquer le build pendant la construction des d\u00e9pendances
Build=Build
Incremental\ build\ -\ only\ build\ changed\ modules=Construction incr\u00E9mentale - ne faire la construction (build) que pour les modules chang\u00E9s
Incremental\ build\ -\ only\ build\ changed\ modules=Construction incr\u00e9mentale - ne faire la construction (build) que pour les modules chang\u00e9s
Maven\ Version=Version de Maven
Root\ POM=POM Racine
Build\ modules\ in\ parallel=Construire les modules en parallèle
Build\ modules\ in\ parallel=Construire les modules en parall\u00eale
Build\ Settings=Configuration du build
Use\ private\ Maven\ repository=Utilise un repository Maven priv\u00E9
Use\ private\ maven\ repository=Utiliser un repository Maven privé
Use\ private\ Maven\ repository=Utilise un repository Maven priv\u00e9
Use\ private\ maven\ repository=Utiliser un repository Maven priv\u00e9
Goals\ and\ options=Goals et options
Maven\ Version.error.1=Jenkins a besoin de savoir où Maven2/3 est installé.
Maven\ Version.error.2=Veuillez le faire dans <a href="{0}/configure" target="_new">la configuration système</a>.
Build\ whenever\ a\ SNAPSHOT\ dependency\ is\ built=Lance un build à chaque fois qu''une dépendance SNAPSHOT est construite
Maven\ Version.error.1=Jenkins a besoin de savoir o\u00f9 Maven2/3 est install\u00c8.
Maven\ Version.error.2=Veuillez le faire dans <a href="{0}/configure" target="_new">la configuration syst\u00cbme</a>.
Build\ whenever\ a\ SNAPSHOT\ dependency\ is\ built=Lance un build \u00e0 chaque fois qu''une d\u00e9pendance SNAPSHOT est construite
Run\ Headless=Ex\u00e9cuter sans environnement graphique
Disable\ automatic\ artifact\ archiving=D\u00e9sactive l'achivage automatique des artefacts
Resolve\ Dependencies\ during\ Pom\ parsing=Effectue la r\u00e9solution de d\u00e9pendances pendant la lecture du POM
Process\ Plugins\ during\ Pom\ parsing=Analyse les plugins pendant la lecture du POM
Maven\ Validation\ Level=Niveau de validation du POM Maven
Goals=Goals
7 changes: 7 additions & 0 deletions maven-plugin/src/main/webapp/run-headless.html
@@ -0,0 +1,7 @@
<div>
<p>
If build doesn't requires access to desktop (only using command line tools and tests) this option can be checked.
<p>
This option allow Jenkins to configure the build process in headless mode. Usefull on OSX to avoid boring Dock icon
to take focus, this option may also in future release be used to select slave adequate instance.
</div>
9 changes: 9 additions & 0 deletions maven-plugin/src/main/webapp/run-headless_fr.html
@@ -0,0 +1,9 @@
<div>
<p>
Si le build ne n&eacute,cessite pas un acc&egrave; &agrave; l'environnement graphique (s'il n'utilise que des outils
en ligne de commande) cette option peut &ecirc;tre activŽe.
<p>
Cette option permet &agrave; Jenkins de lancer le processus de build en mode <em>'headless'</em>. Ceci est
particuli&egrave;rement int&eacute;ressant sur OSX pour &eacute;viter qu'une ic&ocirc;ne Java prenne le focus en sautillant
dans le Dock. Cette option pourrait &agrave; l'avenir servir &agrave; s&eacute;lectionner un esclave adapt&eacute;.
</div>

0 comments on commit a84188e

Please sign in to comment.