Search in sources :

Example 21 with FilePath

use of hudson.FilePath in project violations-plugin by jenkinsci.

the class ViolationsReportBuilder method perform.

public ViolationsReportAsserter perform() throws Exception {
    ViolationsConfig config = new ViolationsConfig();
    config.setSourcePathPattern(sourcePathPattern);
    TypeConfig typeConfig = new TypeConfig(typeDescriptor.getName());
    typeConfig.setPattern(sourcePathPattern);
    config.getTypeConfigs().put(typeDescriptor.getName(), typeConfig);
    FilePath workspace = new FilePath(projectRootDir());
    FilePath targetPath = new FilePath(new File(projectRootDir().getPath() + "/" + VIOLATIONS));
    FilePath htmlPath = new FilePath(projectRootDir());
    AbstractBuild<?, ?> build = mock(Build.class);
    when(build.getRootDir()).thenReturn(projectRootDir());
    BuildListener listener = mock(BuildListener.class);
    ViolationsReport violationsReport = createBuildAction(workspace, targetPath, htmlPath, config, build, listener).getReport();
    return assertThat(violationsReport, typeDescriptor);
}
Also used : FilePath(hudson.FilePath) BuildListener(hudson.model.BuildListener) File(java.io.File)

Example 22 with FilePath

use of hudson.FilePath in project hudson-2.x by hudson.

the class InstallPluginCommand method run.

protected int run() throws Exception {
    Hudson h = Hudson.getInstance();
    h.checkPermission(Hudson.ADMINISTER);
    for (String source : sources) {
        // is this a file?
        FilePath f = new FilePath(channel, source);
        if (f.exists()) {
            stdout.println(Messages.InstallPluginCommand_InstallingPluginFromLocalFile(f));
            if (name == null)
                name = f.getBaseName();
            f.copyTo(getTargetFile());
            continue;
        }
        // is this an URL?
        try {
            URL u = new URL(source);
            stdout.println(Messages.InstallPluginCommand_InstallingPluginFromUrl(u));
            if (name == null) {
                name = u.getPath();
                name = name.substring(name.indexOf('/') + 1);
                name = name.substring(name.indexOf('\\') + 1);
                int idx = name.lastIndexOf('.');
                if (idx > 0)
                    name = name.substring(0, idx);
            }
            getTargetFile().copyFrom(u);
            continue;
        } catch (MalformedURLException e) {
        // not an URL
        }
        // is this a plugin the update center?
        UpdateSite.Plugin p = h.getUpdateCenter().getPlugin(source);
        if (p != null) {
            stdout.println(Messages.InstallPluginCommand_InstallingFromUpdateCenter(source));
            p.deploy().get();
            continue;
        }
        stdout.println(Messages.InstallPluginCommand_NotAValidSourceName(source));
        if (!source.contains(".") && !source.contains(":") && !source.contains("/") && !source.contains("\\")) {
            // looks like a short plugin name. Why did we fail to find it in the update center?
            if (h.getUpdateCenter().getSites().isEmpty()) {
                stdout.println(Messages.InstallPluginCommand_NoUpdateCenterDefined());
            } else {
                Set<String> candidates = new HashSet<String>();
                for (UpdateSite s : h.getUpdateCenter().getSites()) {
                    Data dt = s.getData();
                    if (dt == null) {
                        stdout.println(Messages.InstallPluginCommand_NoUpdateDataRetrieved(s.getUrl()));
                    } else {
                        candidates.addAll(dt.plugins.keySet());
                    }
                }
                stdout.println(Messages.InstallPluginCommand_DidYouMean(source, EditDistance.findNearest(source, candidates)));
            }
        }
        return 1;
    }
    if (restart)
        h.restart();
    // all success
    return 0;
}
Also used : FilePath(hudson.FilePath) MalformedURLException(java.net.MalformedURLException) Hudson(hudson.model.Hudson) Data(hudson.model.UpdateSite.Data) UpdateSite(hudson.model.UpdateSite) URL(java.net.URL) HashSet(java.util.HashSet)

Example 23 with FilePath

use of hudson.FilePath in project blueocean-plugin by jenkinsci.

the class PipelineStepImpl method convert.

private Object convert(String name, ParameterValue v) throws IOException, InterruptedException {
    if (v instanceof FileParameterValue) {
        FileParameterValue fv = (FileParameterValue) v;
        FilePath fp = new FilePath(node.getRun().getRootDir()).child(name);
        fp.copyFrom(fv.getFile());
        return fp;
    } else {
        return v.getValue();
    }
}
Also used : FilePath(hudson.FilePath) FileParameterValue(hudson.model.FileParameterValue)

Example 24 with FilePath

use of hudson.FilePath in project blueocean-plugin by jenkinsci.

the class PipelineApiTest method testArtifactsRunApi.

@Test
public void testArtifactsRunApi() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject("pipeline1");
    p.getBuildersList().add(new TestBuilder() {

        @Override
        public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
            FilePath ws = build.getWorkspace();
            if (ws == null) {
                return false;
            }
            FilePath dir = ws.child("dir");
            dir.mkdirs();
            dir.child("fizz").write("contents", null);
            dir.child("lodge").symlinkTo("fizz", listener);
            return true;
        }
    });
    ArtifactArchiver aa = new ArtifactArchiver("dir/fizz");
    aa.setAllowEmptyArchive(true);
    p.getPublishersList().add(aa);
    FreeStyleBuild b = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
    List artifacts = get("/organizations/jenkins/pipelines/pipeline1/runs/" + b.getId() + "/artifacts", List.class);
    assertEquals(1, artifacts.size());
    assertEquals("fizz", ((Map) artifacts.get(0)).get("name"));
    String artifactName = (String) ((Map) artifacts.get(0)).get("name");
    String name = ArtifactImpl.class.getName() + ":" + artifactName;
    ArtifactContainerImpl container = new ArtifactContainerImpl(b, new Reachable() {

        @Override
        public Link getLink() {
            return new Link("/blue/rest/organizations/jenkins/pipelines/pipeline1/runs/1/artifacts/");
        }
    });
    BlueArtifact blueArtifact = container.get(name);
    assertNotNull(blueArtifact);
}
Also used : FilePath(hudson.FilePath) ArtifactArchiver(hudson.tasks.ArtifactArchiver) IOException(java.io.IOException) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) TestBuilder(org.jvnet.hudson.test.TestBuilder) BuildListener(hudson.model.BuildListener) Reachable(io.jenkins.blueocean.rest.Reachable) BlueArtifact(io.jenkins.blueocean.rest.model.BlueArtifact) Launcher(hudson.Launcher) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ArtifactContainerImpl(io.jenkins.blueocean.service.embedded.rest.ArtifactContainerImpl) Link(io.jenkins.blueocean.rest.hal.Link) Test(org.junit.Test)

Example 25 with FilePath

use of hudson.FilePath in project hudson-2.x by hudson.

the class CommandInstaller method performInstallation.

public FilePath performInstallation(ToolInstallation tool, Node node, TaskListener log) throws IOException, InterruptedException {
    FilePath dir = preferredLocation(tool, node);
    // XXX support Windows batch scripts, Unix scripts with interpreter line, etc. (see CommandInterpreter subclasses)
    FilePath script = dir.createTextTempFile("hudson", ".sh", command);
    try {
        String[] cmd = { "sh", "-e", script.getRemote() };
        int r = node.createLauncher(log).launch().cmds(cmd).stdout(log).pwd(dir).join();
        if (r != 0) {
            throw new IOException("Command returned status " + r);
        }
    } finally {
        script.delete();
    }
    return dir.child(toolHome);
}
Also used : FilePath(hudson.FilePath) IOException(java.io.IOException)

Aggregations

FilePath (hudson.FilePath)39 IOException (java.io.IOException)17 File (java.io.File)12 URL (java.net.URL)5 EnvVars (hudson.EnvVars)4 List (java.util.List)4 AbortException (hudson.AbortException)3 Launcher (hudson.Launcher)3 PrintStream (java.io.PrintStream)3 ImmutableList (com.google.common.collect.ImmutableList)2 BuildListener (hudson.model.BuildListener)2 VirtualChannel (hudson.remoting.VirtualChannel)2 NullSCM (hudson.scm.NullSCM)2 SCM (hudson.scm.SCM)2 WorkspaceList (hudson.slaves.WorkspaceList)2 ArgumentListBuilder (hudson.util.ArgumentListBuilder)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 WindowsSlaveInstaller (hudson.lifecycle.WindowsSlaveInstaller)1