1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Eclipse Public License, Version 1.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.eclipse.org/org/documents/epl-v10.php
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.ide.eclipse.adt.internal.wizards.exportgradle;
import com.android.ide.eclipse.adt.AdtPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.ui.IExportWizard;
import org.eclipse.ui.IWorkbench;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
public class GradleExportWizard extends Wizard implements IExportWizard {
private ProjectSetupBuilder mBuilder = new ProjectSetupBuilder();
private ProjectSelectionPage mFirstPage;
private ConfirmationPage mSecondPage;
private FinalPage mFinalPage;
/**
* Creates buildfile.
*/
@Override
public boolean performFinish() {
if (mBuilder.canGenerate()) {
generateBuildfiles(mSecondPage);
getContainer().showPage(mFinalPage);
return false;
}
return true;
}
@Override
public void addPages() {
addPage(new ImportInsteadPage());
mFirstPage = new ProjectSelectionPage(mBuilder);
addPage(mFirstPage);
mSecondPage = new ConfirmationPage(mBuilder);
addPage(mSecondPage);
mFinalPage = new FinalPage(mBuilder);
addPage(mFinalPage);
}
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
setWindowTitle(ExportMessages.WindowTitle);
setNeedsProgressMonitor(true);
}
@Override
public boolean canFinish() {
return mBuilder.canFinish() || mBuilder.canGenerate();
}
/**
* Converts Eclipse Java projects to Gradle build files. Displays error dialogs.
*/
public boolean generateBuildfiles(final WizardPage page) {
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor pm) throws InterruptedException {
Collection<GradleModule> modules = mBuilder.getModules();
final int count = modules.size();
SubMonitor localmonitor = SubMonitor.convert(pm, ExportMessages.StatusMessage,
count);
BuildFileCreator.createBuildFiles(
mBuilder,
page.getShell(),
localmonitor.newChild(count));
}
};
try {
getContainer().run(false, false, runnable);
} catch (InvocationTargetException e) {
AdtPlugin.log(e, null);
return false;
} catch (InterruptedException e) {
AdtPlugin.log(e, null);
return false;
}
if (page.getErrorMessage() != null) {
return false;
}
return true;
}
}
|