2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.client
.ui
.dist
.wizards
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
21 import javax
.jcr
.Node
;
22 import javax
.jcr
.NodeIterator
;
23 import javax
.jcr
.RepositoryException
;
24 import javax
.jcr
.Session
;
26 import org
.apache
.commons
.logging
.Log
;
27 import org
.apache
.commons
.logging
.LogFactory
;
28 import org
.argeo
.ArgeoMonitor
;
29 import org
.argeo
.eclipse
.ui
.EclipseArgeoMonitor
;
30 import org
.argeo
.jcr
.JcrUtils
;
31 import org
.argeo
.slc
.SlcException
;
32 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
33 import org
.argeo
.slc
.client
.ui
.dist
.PrivilegedJob
;
34 import org
.argeo
.slc
.client
.ui
.dist
.utils
.ViewerUtils
;
35 import org
.argeo
.slc
.jcr
.SlcTypes
;
36 import org
.argeo
.slc
.repo
.RepoConstants
;
37 import org
.argeo
.slc
.repo
.RepoService
;
38 import org
.argeo
.slc
.repo
.RepoUtils
;
39 import org
.argeo
.slc
.repo
.maven
.GenerateBinaries
;
40 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
41 import org
.eclipse
.core
.runtime
.IStatus
;
42 import org
.eclipse
.core
.runtime
.Status
;
43 import org
.eclipse
.jface
.dialogs
.IMessageProvider
;
44 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
45 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
46 import org
.eclipse
.jface
.viewers
.IStructuredContentProvider
;
47 import org
.eclipse
.jface
.viewers
.TableViewer
;
48 import org
.eclipse
.jface
.viewers
.TableViewerColumn
;
49 import org
.eclipse
.jface
.viewers
.Viewer
;
50 import org
.eclipse
.jface
.viewers
.ViewerComparator
;
51 import org
.eclipse
.jface
.wizard
.IWizardPage
;
52 import org
.eclipse
.jface
.wizard
.Wizard
;
53 import org
.eclipse
.jface
.wizard
.WizardPage
;
54 import org
.eclipse
.swt
.SWT
;
55 import org
.eclipse
.swt
.layout
.GridData
;
56 import org
.eclipse
.swt
.layout
.GridLayout
;
57 import org
.eclipse
.swt
.widgets
.Button
;
58 import org
.eclipse
.swt
.widgets
.Composite
;
59 import org
.eclipse
.swt
.widgets
.Label
;
60 import org
.eclipse
.swt
.widgets
.Table
;
61 import org
.eclipse
.swt
.widgets
.Text
;
62 import org
.sonatype
.aether
.artifact
.Artifact
;
65 * Define parameters to asynchronously generate binaries, sources and sdk pom
66 * artifacts for this group using a {@link GenerateBinaries} runnable
68 public class GenerateBinariesWizard
extends Wizard
{
69 private final static Log log
= LogFactory
70 .getLog(GenerateBinariesWizard
.class);
73 private final RepoService repoService
;
74 private final String repoNodePath
;
75 private String wkspName
;
76 private String groupNodePath
;
79 private RecapPage recapPage
;
81 // Controls with parameters
82 private Text versionTxt
;
83 private Text latestVersionTxt
;
84 private Text highestArtifactVersionTxt
;
86 public GenerateBinariesWizard(RepoService repoService
, String repoNodePath
,
87 String wkspName
, String groupNodePath
) {
89 this.repoService
= repoService
;
90 this.repoNodePath
= repoNodePath
;
91 this.wkspName
= wkspName
;
92 this.groupNodePath
= groupNodePath
;
96 public void dispose() {
101 public void addPages() {
103 recapPage
= new RecapPage();
105 setWindowTitle("Define Binary Generation Procedure");
106 } catch (Exception e
) {
107 throw new SlcException("Cannot add page to wizard ", e
);
112 public boolean performFinish() {
116 String msg
= "Your are about to generate binaries, sources and sdk "
117 + "pom artifacts for this group, "
118 + "do you really want to proceed ?";
120 boolean result
= MessageDialog
.openConfirm(DistPlugin
.getDefault()
121 .getWorkbench().getDisplay().getActiveShell(),
122 "Confirm Launch", msg
);
125 GenerateBinaryJob job
= new GenerateBinaryJob(repoService
,
126 repoNodePath
, wkspName
, groupNodePath
,
127 versionTxt
.getText());
131 } catch (Exception e
) {
132 throw new SlcException(
133 "Unexpected error while launching the fetch", e
);
138 // ///////////////////////////////
140 private class RecapPage
extends WizardPage
{
142 private TableViewer recapViewer
;
145 super("Define parameters and launch");
146 setTitle("Define parameters and launch");
150 public boolean isPageComplete() {
151 return isCurrentPage();
154 public IWizardPage
getNextPage() {
155 return null; // always last
158 private void refreshValues() {
159 Session session
= null;
161 session
= repoService
.getRemoteSession(repoNodePath
, null,
163 Node groupNode
= session
.getNode(groupNodePath
);
164 GenerateBinaries gb
= GenerateBinaries
.preProcessGroupNode(
167 List
<Artifact
> binaries
= new ArrayList
<Artifact
>();
168 binaries
.addAll(gb
.getBinaries());
170 Artifact highestVersion
= gb
.getHighestArtifactVersion();
171 if (highestVersion
!= null)
172 highestArtifactVersionTxt
.setText(highestVersion
175 if (groupNode
.hasNode(RepoConstants
.BINARIES_ARTIFACT_ID
)) {
176 Node binaryNode
= groupNode
177 .getNode(RepoConstants
.BINARIES_ARTIFACT_ID
);
178 Artifact currHighestVersion
= null;
179 for (NodeIterator ni
= binaryNode
.getNodes(); ni
.hasNext();) {
180 Node currN
= ni
.nextNode();
182 .isNodeType(SlcTypes
.SLC_ARTIFACT_VERSION_BASE
)) {
183 Artifact currVersion
= RepoUtils
.asArtifact(currN
);
185 if (currHighestVersion
== null
186 || currVersion
.getBaseVersion()
189 .getBaseVersion()) > 0)
190 currHighestVersion
= currVersion
;
193 if (currHighestVersion
!= null)
194 latestVersionTxt
.setText(currHighestVersion
197 recapViewer
.setInput(binaries
);
198 recapViewer
.refresh();
199 } catch (RepositoryException re
) {
200 throw new SlcException("Unable to get repositories URIs", re
);
202 JcrUtils
.logoutQuietly(session
);
206 public void createControl(Composite parent
) {
207 setMessage("Configure Maven Indexing", IMessageProvider
.NONE
);
209 Composite composite
= new Composite(parent
, SWT
.NO_FOCUS
);
210 composite
.setLayout(new GridLayout(2, false));
212 versionTxt
= createLT(composite
, "Version");
214 .setToolTipText("Enter a version for the new Modular Distribution");
216 latestVersionTxt
= createLT(composite
, "Latest version");
217 latestVersionTxt
.setEditable(false);
219 .setToolTipText("The actual latest version of this modular distribution");
221 highestArtifactVersionTxt
= createLT(composite
,
222 "Highest version in current category");
223 highestArtifactVersionTxt
.setEditable(false);
224 highestArtifactVersionTxt
225 .setToolTipText("The highest version among all version of the below listed modules.");
228 Table table
= new Table(composite
, SWT
.H_SCROLL
| SWT
.V_SCROLL
230 table
.setLinesVisible(true);
231 table
.setHeaderVisible(true);
232 table
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 2,
234 recapViewer
= new TableViewer(table
);
236 TableViewerColumn column
= ViewerUtils
.createTableViewerColumn(
237 recapViewer
, "Name", SWT
.NONE
, 250);
238 column
.setLabelProvider(new ColumnLabelProvider() {
240 public String
getText(Object element
) {
241 return ((Artifact
) element
).getArtifactId();
245 column
= ViewerUtils
.createTableViewerColumn(recapViewer
,
246 "Version", SWT
.NONE
, 250);
247 column
.setLabelProvider(new ColumnLabelProvider() {
249 public String
getText(Object element
) {
250 return ((Artifact
) element
).getBaseVersion();
254 recapViewer
.setContentProvider(new IStructuredContentProvider() {
255 List
<Artifact
> artifacts
;
257 @SuppressWarnings("unchecked")
258 public void inputChanged(Viewer viewer
, Object oldInput
,
260 artifacts
= (List
<Artifact
>) newInput
;
261 if (artifacts
!= null)
262 recapViewer
.refresh();
265 public void dispose() {
268 public Object
[] getElements(Object inputElement
) {
269 return artifacts
== null ?
null : artifacts
.toArray();
273 // A basic comparator
274 recapViewer
.setComparator(new ViewerComparator());
276 setControl(composite
);
281 * Define the privileged job that will be run asynchronously generate
282 * corresponding artifacts
284 private class GenerateBinaryJob
extends PrivilegedJob
{
286 private final RepoService repoService
;
287 private final String repoNodePath
;
288 private final String wkspName
;
289 private final String groupNodePath
;
290 private final String version
;
292 public GenerateBinaryJob(RepoService repoService
, String repoNodePath
,
293 String wkspName
, String groupNodePath
, String version
) {
295 this.version
= version
;
296 this.repoService
= repoService
;
297 this.repoNodePath
= repoNodePath
;
298 this.wkspName
= wkspName
;
299 this.groupNodePath
= groupNodePath
;
303 protected IStatus
doRun(IProgressMonitor progressMonitor
) {
304 Session session
= null;
306 ArgeoMonitor monitor
= new EclipseArgeoMonitor(progressMonitor
);
307 session
= repoService
.getRemoteSession(repoNodePath
, null,
309 Node groupBaseNode
= session
.getNode(groupNodePath
);
310 GenerateBinaries
.processGroupNode(groupBaseNode
, version
,
312 } catch (Exception e
) {
313 if (log
.isDebugEnabled())
315 return new Status(IStatus
.ERROR
, DistPlugin
.ID
,
316 "Cannot normalize group", e
);
318 JcrUtils
.logoutQuietly(session
);
320 return Status
.OK_STATUS
;
324 // ////////////////////////////
326 /** Creates label and text. */
327 protected Text
createLT(Composite parent
, String label
) {
328 new Label(parent
, SWT
.NONE
).setText(label
);
329 Text text
= new Text(parent
, SWT
.SINGLE
| SWT
.LEAD
| SWT
.BORDER
331 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
335 /** Creates label and check. */
336 protected Button
createLC(Composite parent
, String label
) {
337 new Label(parent
, SWT
.NONE
).setText(label
);
338 Button check
= new Button(parent
, SWT
.CHECK
);
339 check
.setSelection(false);
340 check
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));