Search in sources :

Example 16 with Launcher

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);
    }
}
Also used : FilePath(hudson.FilePath) Launcher(hudson.Launcher) ProcStarter(hudson.Launcher.ProcStarter) IOException(java.io.IOException) File(java.io.File) URLConnection(java.net.URLConnection)

Example 17 with Launcher

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"));
}
Also used : FilePath(hudson.FilePath) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TestBuilder(org.jvnet.hudson.test.TestBuilder) Launcher(hudson.Launcher) File(java.io.File) Test(org.junit.Test)

Example 18 with Launcher

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());
}
Also used : FilePath(hudson.FilePath) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TestBuilder(org.jvnet.hudson.test.TestBuilder) Launcher(hudson.Launcher) File(java.io.File) Test(org.junit.Test)

Example 19 with Launcher

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());
}
Also used : FilePath(hudson.FilePath) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TestBuilder(org.jvnet.hudson.test.TestBuilder) Launcher(hudson.Launcher) File(java.io.File) Test(org.junit.Test)

Example 20 with Launcher

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() {
            };
        }
    };
}
Also used : FilePath(hudson.FilePath) Launcher(hudson.Launcher) BuildWrapper(hudson.tasks.BuildWrapper)

Aggregations

Launcher (hudson.Launcher)20 IOException (java.io.IOException)17 FilePath (hudson.FilePath)14 Test (org.junit.Test)11 TestBuilder (org.jvnet.hudson.test.TestBuilder)11 File (java.io.File)8 FreeStyleProject (hudson.model.FreeStyleProject)7 ArrayList (java.util.ArrayList)6 BuildListener (hudson.model.BuildListener)5 EnvVars (hudson.EnvVars)3 FreeStyleBuild (hudson.model.FreeStyleBuild)3 TaskListener (hudson.model.TaskListener)3 ArtifactArchiver (hudson.tasks.ArtifactArchiver)3 AbortException (hudson.AbortException)2 PollingResult (hudson.scm.PollingResult)2 SCMRevisionState (hudson.scm.SCMRevisionState)2 WorkspaceList (hudson.slaves.WorkspaceList)2 Verifier (jenkins.plugins.nodejs.CIBuilderHelper.Verifier)2 DetectionFailedException (jenkins.plugins.nodejs.tools.DetectionFailedException)2 NodeJSInstallation (jenkins.plugins.nodejs.tools.NodeJSInstallation)2