Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 317384 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/builds/core/IBuildPlan.java (+5 lines)
Lines 13-18 Link Here
13
13
14
import java.util.List;
14
import java.util.List;
15
15
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IStatus;
18
16
/**
19
/**
17
 * @author Steffen Pingel
20
 * @author Steffen Pingel
18
 */
21
 */
Lines 38-41 Link Here
38
41
39
	public IBuildPlanWorkingCopy createWorkingCopy();
42
	public IBuildPlanWorkingCopy createWorkingCopy();
40
43
44
	IStatus run(IOperationMonitor monitor) throws CoreException;
45
41
}
46
}
(-)src/org/eclipse/mylyn/builds/core/spi/BuildServerBehaviour.java (+3 lines)
Lines 15-20 Link Here
15
15
16
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.mylyn.builds.core.IBuildElement;
18
import org.eclipse.mylyn.builds.core.IBuildPlan;
19
import org.eclipse.mylyn.builds.core.IBuildPlan;
19
import org.eclipse.mylyn.builds.core.IBuildServer;
20
import org.eclipse.mylyn.builds.core.IBuildServer;
20
import org.eclipse.mylyn.builds.core.IOperationMonitor;
21
import org.eclipse.mylyn.builds.core.IOperationMonitor;
Lines 38-41 Link Here
38
39
39
	public abstract IStatus validate(IOperationMonitor monitor) throws CoreException;
40
	public abstract IStatus validate(IOperationMonitor monitor) throws CoreException;
40
41
42
	public abstract IStatus runBuild(IBuildElement element, IOperationMonitor monitor) throws CoreException;
43
41
}
44
}
(-)src/org/eclipse/mylyn/internal/builds/core/BuildPlan.java (+7 lines)
Lines 8-13 Link Here
8
8
9
import java.util.Collection;
9
import java.util.Collection;
10
10
11
import org.eclipse.core.runtime.CoreException;
12
import org.eclipse.core.runtime.IStatus;
11
import org.eclipse.emf.common.notify.Notification;
13
import org.eclipse.emf.common.notify.Notification;
12
import org.eclipse.emf.common.notify.NotificationChain;
14
import org.eclipse.emf.common.notify.NotificationChain;
13
import org.eclipse.emf.common.util.EList;
15
import org.eclipse.emf.common.util.EList;
Lines 24-29 Link Here
24
import org.eclipse.mylyn.builds.core.IBuildPlan;
26
import org.eclipse.mylyn.builds.core.IBuildPlan;
25
import org.eclipse.mylyn.builds.core.IBuildPlanWorkingCopy;
27
import org.eclipse.mylyn.builds.core.IBuildPlanWorkingCopy;
26
import org.eclipse.mylyn.builds.core.IBuildServer;
28
import org.eclipse.mylyn.builds.core.IBuildServer;
29
import org.eclipse.mylyn.builds.core.IOperationMonitor;
27
30
28
/**
31
/**
29
 * <!-- begin-user-doc -->
32
 * <!-- begin-user-doc -->
Lines 1085-1088 Link Here
1085
		return newPlan;
1088
		return newPlan;
1086
	}
1089
	}
1087
1090
1091
	public IStatus run(IOperationMonitor monitor) throws CoreException {
1092
		return ((BuildServer) getServer()).getBehaviour().runBuild(this, monitor);
1093
	}
1094
1088
} // BuildPlan
1095
} // BuildPlan
(-)src/org/eclipse/mylyn/internal/builds/ui/view/BuildsView.java (-2 / +15 lines)
Lines 117-122 Link Here
117
		MenuManager menuManager = new MenuManager();
117
		MenuManager menuManager = new MenuManager();
118
118
119
		GroupMarker marker = new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS);
119
		GroupMarker marker = new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS);
120
121
		OpenInBrowserAction openInBrowserAction = new OpenInBrowserAction();
122
		menuManager.add(openInBrowserAction);
123
		viewer.addSelectionChangedListener(openInBrowserAction);
124
125
		RunBuildAction runBuildAction = new RunBuildAction();
126
		menuManager.add(runBuildAction);
127
		viewer.addSelectionChangedListener(runBuildAction);
128
120
		menuManager.add(marker);
129
		menuManager.add(marker);
121
		Menu contextMenu = menuManager.createContextMenu(parent);
130
		Menu contextMenu = menuManager.createContextMenu(parent);
122
131
Lines 130-137 Link Here
130
		tree.setHeaderVisible(true);
139
		tree.setHeaderVisible(true);
131
140
132
		TreeViewerColumn buildViewerColumn = new TreeViewerColumn(viewer, SWT.LEFT);
141
		TreeViewerColumn buildViewerColumn = new TreeViewerColumn(viewer, SWT.LEFT);
133
		buildViewerColumn.setLabelProvider(new DecoratingStyledCellLabelProvider(new BuildLabelProvider(),
142
		buildViewerColumn.setLabelProvider(new DecoratingStyledCellLabelProvider(new BuildLabelProvider(), PlatformUI
134
				PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator(), null));
143
				.getWorkbench().getDecoratorManager().getLabelDecorator(), null));
135
		TreeColumn buildColumn = buildViewerColumn.getColumn();
144
		TreeColumn buildColumn = buildViewerColumn.getColumn();
136
		buildColumn.setText("Builds");
145
		buildColumn.setText("Builds");
137
		buildColumn.setWidth(220);
146
		buildColumn.setWidth(220);
Lines 198-203 Link Here
198
		OpenInBrowserAction openInBrowserAction = new OpenInBrowserAction();
207
		OpenInBrowserAction openInBrowserAction = new OpenInBrowserAction();
199
		viewer.addSelectionChangedListener(openInBrowserAction);
208
		viewer.addSelectionChangedListener(openInBrowserAction);
200
		manager.add(openInBrowserAction);
209
		manager.add(openInBrowserAction);
210
211
		RunBuildAction runBuildAction = new RunBuildAction();
212
		viewer.addSelectionChangedListener(runBuildAction);
213
		manager.add(runBuildAction);
201
	}
214
	}
202
215
203
	TreeViewer getViewer() {
216
	TreeViewer getViewer() {
(-)src/org/eclipse/mylyn/internal/builds/ui/view/RunBuildAction.java (+69 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 Markus Knittig and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Markus Knittig - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.internal.builds.ui.view;
13
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.NullProgressMonitor;
18
import org.eclipse.core.runtime.OperationCanceledException;
19
import org.eclipse.core.runtime.Status;
20
import org.eclipse.core.runtime.jobs.Job;
21
import org.eclipse.jface.viewers.IStructuredSelection;
22
import org.eclipse.mylyn.builds.core.IBuildPlan;
23
import org.eclipse.mylyn.builds.core.util.ProgressUtil;
24
import org.eclipse.mylyn.internal.builds.core.BuildsCorePlugin;
25
import org.eclipse.mylyn.internal.builds.ui.BuildImages;
26
import org.eclipse.osgi.util.NLS;
27
import org.eclipse.ui.actions.BaseSelectionListenerAction;
28
29
/**
30
 * @author Markus Knittig
31
 */
32
public class RunBuildAction extends BaseSelectionListenerAction {
33
34
	protected RunBuildAction() {
35
		super("Run Build");
36
		setToolTipText("Run Build");
37
		setImageDescriptor(BuildImages.RUN);
38
		setDisabledImageDescriptor(BuildImages.RUN_DISABLED);
39
	}
40
41
	@Override
42
	protected boolean updateSelection(IStructuredSelection selection) {
43
		return (selection.getFirstElement() instanceof IBuildPlan);
44
	}
45
46
	@Override
47
	public void run() {
48
49
		IStructuredSelection selection = getStructuredSelection();
50
		for (Object object : selection.toList()) {
51
			if (object instanceof IBuildPlan) {
52
				final IBuildPlan plan = (IBuildPlan) object;
53
				new Job("Running build...") {
54
					@Override
55
					protected IStatus run(IProgressMonitor monitor) {
56
						try {
57
							return plan.run(ProgressUtil.convert(monitor));
58
						} catch (CoreException e) {
59
							return new Status(IStatus.ERROR, BuildsCorePlugin.ID_PLUGIN, NLS.bind(
60
									"Run of build ''{0}'' failed", plan.getName(), e));
61
						} catch (OperationCanceledException e) {
62
							return Status.CANCEL_STATUS;
63
						}
64
					}
65
				}.run(new NullProgressMonitor());
66
			}
67
		}
68
	}
69
}
(-)src/org/eclipse/mylyn/internal/hudson/core/HudsonServerBehaviour.java (+12 lines)
Lines 18-23 Link Here
18
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.mylyn.builds.core.BuildState;
19
import org.eclipse.mylyn.builds.core.BuildState;
20
import org.eclipse.mylyn.builds.core.BuildStatus;
20
import org.eclipse.mylyn.builds.core.BuildStatus;
21
import org.eclipse.mylyn.builds.core.IBuildElement;
21
import org.eclipse.mylyn.builds.core.IBuildPlan;
22
import org.eclipse.mylyn.builds.core.IBuildPlan;
22
import org.eclipse.mylyn.builds.core.IBuildPlanWorkingCopy;
23
import org.eclipse.mylyn.builds.core.IBuildPlanWorkingCopy;
23
import org.eclipse.mylyn.builds.core.IBuildServer;
24
import org.eclipse.mylyn.builds.core.IBuildServer;
Lines 102-105 Link Here
102
		}
103
		}
103
	}
104
	}
104
105
106
	@Override
107
	public IStatus runBuild(IBuildElement element, IOperationMonitor monitor) throws CoreException {
108
		try {
109
			HudsonModelJob job = new HudsonModelJob();
110
			job.setUrl(element.getUrl());
111
			return client.runBuild(job, monitor);
112
		} catch (HudsonException e) {
113
			throw HudsonCorePlugin.toCoreException(e);
114
		}
115
	}
116
105
}
117
}
(-)src/org/eclipse/mylyn/internal/hudson/core/client/RestfulHudsonClient.java (+20 lines)
Lines 53-58 Link Here
53
53
54
	public RestfulHudsonClient(AbstractWebLocation location) {
54
	public RestfulHudsonClient(AbstractWebLocation location) {
55
		client = new CommonHttpClient(location);
55
		client = new CommonHttpClient(location);
56
		client.getHttpClient().getParams().setAuthenticationPreemptive(true);
56
	}
57
	}
57
58
58
	protected void checkResponse(int statusCode) throws HudsonException {
59
	protected void checkResponse(int statusCode) throws HudsonException {
Lines 128-131 Link Here
128
				HttpStatus.getStatusText(response)));
129
				HttpStatus.getStatusText(response)));
129
	}
130
	}
130
131
132
	public IStatus runBuild(final HudsonModelJob job, final IOperationMonitor monitor) throws HudsonException {
133
		int response = new HudsonOperation<Integer>(client) {
134
			@Override
135
			public Integer execute() throws IOException {
136
				CommonHttpMethod method = createGetMethod(job.getUrl() + "/build");
137
				try {
138
					return execute(method, monitor);
139
				} finally {
140
					method.releaseConnection(monitor);
141
				}
142
			}
143
		}.run();
144
		if (response == HttpStatus.SC_OK) {
145
			return Status.OK_STATUS;
146
		}
147
		throw new HudsonException(NLS.bind("Unexpected return code {0}: {1}", response,
148
				HttpStatus.getStatusText(response)));
149
	}
150
131
}
151
}
(-)src/org/eclipse/mylyn/hudson/tests/client/HudsonClientTest.java (-3 / +34 lines)
Lines 20-26 Link Here
20
import org.eclipse.mylyn.hudson.tests.support.HudsonFixture;
20
import org.eclipse.mylyn.hudson.tests.support.HudsonFixture;
21
import org.eclipse.mylyn.internal.hudson.core.client.HudsonException;
21
import org.eclipse.mylyn.internal.hudson.core.client.HudsonException;
22
import org.eclipse.mylyn.internal.hudson.core.client.RestfulHudsonClient;
22
import org.eclipse.mylyn.internal.hudson.core.client.RestfulHudsonClient;
23
import org.eclipse.mylyn.internal.hudson.model.HudsonModelBallColor;
23
import org.eclipse.mylyn.internal.hudson.model.HudsonModelJob;
24
import org.eclipse.mylyn.internal.hudson.model.HudsonModelJob;
25
import org.eclipse.mylyn.tests.util.TestUtil;
26
import org.eclipse.mylyn.tests.util.TestUtil.Credentials;
27
import org.eclipse.mylyn.tests.util.TestUtil.PrivilegeLevel;
24
28
25
/**
29
/**
26
 * Test cases for {@link RestfulHudsonClient}.
30
 * Test cases for {@link RestfulHudsonClient}.
Lines 60-69 Link Here
60
		}
64
		}
61
	}
65
	}
62
66
63
	public void testGetPlans() throws Exception {
67
	public void testGetJobs() throws Exception {
64
		client = fixture.connect();
68
		client = fixture.connect();
65
		List<HudsonModelJob> plans = client.getJobs(null);
69
		List<HudsonModelJob> jobs = client.getJobs(null);
66
		assertEquals(plans.get(0).getName(), "failing");
70
		assertEquals(jobs.get(0).getName(), "failing");
71
	}
72
73
	public void testRunBuild() throws Exception {
74
		Credentials credentials = TestUtil.readCredentials(PrivilegeLevel.USER);
75
76
		client = fixture.connect(HudsonFixture.HUDSON_TEST_URL, credentials.username, credentials.password);
77
78
		// failing build
79
		client.runBuild(getJob("failing"), ProgressUtil.convert(null));
80
		assertEquals(getJob("failing").getColor(), HudsonModelBallColor.RED_ANIME);
81
		Thread.sleep(1000);
82
		assertEquals(getJob("succeeding").getColor(), HudsonModelBallColor.RED);
83
84
		// succeeding build
85
		client.runBuild(getJob("succeeding"), ProgressUtil.convert(null));
86
		assertEquals(getJob("succeeding").getColor(), HudsonModelBallColor.BLUE_ANIME);
87
		Thread.sleep(1000);
88
		assertEquals(getJob("succeeding").getColor(), HudsonModelBallColor.BLUE);
89
	}
90
91
	private HudsonModelJob getJob(String name) throws HudsonException {
92
		for (HudsonModelJob job : client.getJobs(null)) {
93
			if (job.getName().equals(name)) {
94
				return job;
95
			}
96
		}
97
		return null;
67
	}
98
	}
68
99
69
}
100
}
(-)src/org/eclipse/mylyn/hudson/tests/support/HudsonFixture.java (-2 / +2 lines)
Lines 30-38 Link Here
30
 */
30
 */
31
public class HudsonFixture extends TestFixture {
31
public class HudsonFixture extends TestFixture {
32
32
33
	private static HudsonFixture current;
33
	public final static String HUDSON_TEST_URL = "http://mylyn.eclipse.org/hudson";
34
34
35
	private final static String HUDSON_TEST_URL = "http://mylyn.eclipse.org/hudson";
35
	private static HudsonFixture current;
36
36
37
	private static final HudsonFixture DEFAULT = new HudsonFixture(HUDSON_TEST_URL, "1.339", "REST");
37
	private static final HudsonFixture DEFAULT = new HudsonFixture(HUDSON_TEST_URL, "1.339", "REST");
38
38

Return to bug 317384