use of hudson.Launcher in project nodejs-plugin by jenkinsci.
the class NodeJSInstaller method installIfNecessaryMSI.
private boolean installIfNecessaryMSI(FilePath expected, URL archive, TaskListener listener, String message) throws IOException, InterruptedException {
try {
URLConnection con;
try {
con = ProxyConfiguration.open(archive);
con.connect();
} catch (IOException x) {
if (expected.exists()) {
// Cannot connect now, so assume whatever was last unpacked is still OK.
if (listener != null) {
listener.getLogger().println("Skipping installation of " + archive + " to " + expected.getRemote() + ": " + x);
}
return false;
} else {
throw x;
}
}
long sourceTimestamp = con.getLastModified();
FilePath timestamp = expected.child(".timestamp");
if (expected.exists()) {
if (timestamp.exists() && sourceTimestamp == timestamp.lastModified()) {
// already up to date
return false;
}
expected.deleteContents();
} else {
expected.mkdirs();
}
if (listener != null) {
listener.getLogger().println(message);
}
FilePath temp = expected.createTempDir("_temp", "");
FilePath msi = temp.child("nodejs.msi");
msi.copyFrom(archive);
try {
Launcher launch = temp.createLauncher(listener);
ProcStarter starter = launch.launch().cmds(new File("cmd"), "/c", "for %A in (.) do msiexec TARGETDIR=\"%~sA\" /a " + temp.getName() + "\\nodejs.msi /qn /L* " + temp.getName() + "\\log.txt");
starter = starter.pwd(expected);
int exitCode = starter.join();
if (exitCode != 0) {
throw new IOException("msiexec failed. exit code: " + exitCode + " Please see the log file " + temp.child("log.txt").getRemote() + " for more informations.", null);
}
if (listener != null) {
listener.getLogger().println("msi install complete");
}
// remove temporary folder
temp.deleteRecursive();
// remove the double msi file in expected folder
FilePath duplicatedMSI = expected.child("nodejs.msi");
if (duplicatedMSI.exists()) {
duplicatedMSI.delete();
}
} catch (IOException e) {
throw new IOException("Failed to install " + archive, e);
}
timestamp.touch(sourceTimestamp);
return true;
} catch (IOException e) {
throw new IOException("Failed to install " + archive + " to " + expected.getRemote(), e);
}
}
use of hudson.Launcher in project htmlpublisher-plugin by jenkinsci.
the class HtmlPublisherIntegrationTest method testWithWildcardPatterns.
@Test
public void testWithWildcardPatterns() throws Exception {
FreeStyleProject p = j.createFreeStyleProject("variable_job");
final String reportDir = "autogen";
p.getBuildersList().add(new TestBuilder() {
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
FilePath ws = build.getWorkspace().child(reportDir);
ws.child("nested1").child("aReportDir").child("nested").child("afile.html").write("hello", "UTF-8");
ws.child("notincluded").child("afile.html").write("hello", "UTF-8");
ws.child("otherDir").child("afile.html").write("hello", "UTF-8");
return true;
}
});
HtmlPublisherTarget target2 = new HtmlPublisherTarget("reportname", reportDir, "**/aReportDir/*/afile.html, **/otherDir/afile.html", true, true, false);
List<HtmlPublisherTarget> targets = new ArrayList<>();
targets.add(target2);
p.getPublishersList().add(new HtmlPublisher(targets));
AbstractBuild build = j.buildAndAssertSuccess(p);
File wrapperFile = new File(build.getRootDir(), "htmlreports/reportname/htmlpublisher-wrapper.html");
assertTrue(wrapperFile.exists());
String content = new String(Files.readAllBytes(wrapperFile.toPath()));
assertTrue(content.contains("nested1/aReportDir/nested/afile.html"));
assertTrue(content.contains("otherDir/afile.html"));
assertFalse(content.contains("notincluded/afile.html"));
}
use of hudson.Launcher in project htmlpublisher-plugin by jenkinsci.
the class HtmlPublisherIntegrationTest method testPublishesTwoReportsOneJob.
@Test
public void testPublishesTwoReportsOneJob() throws Exception {
FreeStyleProject p = j.createFreeStyleProject("variable_job");
p.getBuildersList().add(new TestBuilder() {
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
FilePath ws = build.getWorkspace();
ws.child("dirA").child("afile.html").write("hello", "UTF-8");
ws.child("dirB").child("bfile.html").write("goodbye", "UTF-8");
return true;
}
});
HtmlPublisherTarget target1 = new HtmlPublisherTarget("reportnameB", "dirB", "", true, true, false);
HtmlPublisherTarget target2 = new HtmlPublisherTarget("reportnameA", "dirA", "", true, true, false);
List<HtmlPublisherTarget> targets = new ArrayList<>();
targets.add(target1);
targets.add(target2);
p.getPublishersList().add(new HtmlPublisher(targets));
AbstractBuild build = j.buildAndAssertSuccess(p);
assertTrue(new File(build.getRootDir(), "htmlreports/reportnameA/htmlpublisher-wrapper.html").exists());
assertTrue(new File(build.getRootDir(), "htmlreports/reportnameB/htmlpublisher-wrapper.html").exists());
}
use of hudson.Launcher in project htmlpublisher-plugin by jenkinsci.
the class HtmlPublisherIntegrationTest method testAllowMissingStillRunsSubsequentReports.
@Test
public void testAllowMissingStillRunsSubsequentReports() throws Exception {
FreeStyleProject p = j.createFreeStyleProject("variable_job");
p.getBuildersList().add(new TestBuilder() {
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
FilePath ws = build.getWorkspace();
ws.child("dirA").child("afile.html").write("hello", "UTF-8");
return true;
}
});
HtmlPublisherTarget target1 = new HtmlPublisherTarget("reportnameB", "dirB", "", true, true, true);
HtmlPublisherTarget target2 = new HtmlPublisherTarget("reportnameA", "dirA", "", true, true, false);
List<HtmlPublisherTarget> targets = new ArrayList<>();
targets.add(target1);
targets.add(target2);
p.getPublishersList().add(new HtmlPublisher(targets));
AbstractBuild build = j.buildAndAssertSuccess(p);
assertTrue(new File(build.getRootDir(), "htmlreports/reportnameA/htmlpublisher-wrapper.html").exists());
assertFalse(new File(build.getRootDir(), "htmlreports/reportnameB/htmlpublisher-wrapper.html").exists());
}
use of hudson.Launcher in project hudson-2.x by hudson.
the class FileParameterValue method createBuildWrapper.
@Override
public BuildWrapper createBuildWrapper(AbstractBuild<?, ?> build) {
return new BuildWrapper() {
@Override
public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
if (!StringUtils.isEmpty(file.getName())) {
listener.getLogger().println("Copying file to " + location);
FilePath locationFilePath = build.getWorkspace().child(location);
locationFilePath.getParent().mkdirs();
locationFilePath.copyFrom(file);
file = null;
locationFilePath.copyTo(new FilePath(getLocationUnderBuild(build)));
}
return new Environment() {
};
}
};
}
Aggregations