Skip to content

Commit e001fb5

Browse files
committed
Merge pull request #734 from BenDol/bd_appgen
Stop swallowing compile errors ApplicationControllerGenerator!
2 parents d819285 + d30fa45 commit e001fb5

File tree

5 files changed

+170
-8
lines changed

5 files changed

+170
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2015 ArcBees Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package com.gwtplatform.mvp.client.fallback;
18+
19+
import com.google.gwt.core.client.GWT;
20+
import com.google.gwt.core.client.Scheduler;
21+
import com.google.gwt.user.client.ui.HTML;
22+
import com.google.gwt.user.client.ui.RootPanel;
23+
import com.gwtplatform.mvp.client.ApplicationController;
24+
25+
public class ApplicationControllerFallback implements ApplicationController {
26+
27+
public static final String REASON = "There must have been an issue generating " +
28+
"the ApplicationController. Please check your module configuration, ensure there " +
29+
"are no compile errors in your source code and ensure you are not importing sources " +
30+
"that cannot be compiled by GWT.";
31+
32+
@Override
33+
public void init() {
34+
GWT.log(REASON);
35+
36+
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
37+
@Override
38+
public void execute() {
39+
RootPanel.get().add(new HTML("<h3>" + REASON + "</h3>"));
40+
}
41+
});
42+
}
43+
44+
@Override
45+
public void onModuleLoad() {
46+
init();
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2015 ArcBees Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package com.gwtplatform.mvp.client.fallback;
18+
19+
import com.google.gwt.core.client.GWT;
20+
import com.google.gwt.core.client.Scheduler;
21+
import com.google.gwt.user.client.ui.HTML;
22+
import com.google.gwt.user.client.ui.RootPanel;
23+
import com.gwtplatform.mvp.client.Bootstrapper;
24+
25+
public class BootstrapperFallback implements Bootstrapper {
26+
27+
private static final String REASON = "There must have been an issue generating the Bootstrapper. " +
28+
"Please check your module configuration, ensure there are no compile errors in your source code " +
29+
"and ensure you are not importing sources that cannot be compiled by GWT.";
30+
31+
@Override
32+
public void onBootstrap() {
33+
GWT.log(REASON);
34+
35+
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
36+
@Override
37+
public void execute() {
38+
RootPanel.get().add(new HTML("<h3>" + REASON + "</h3>"));
39+
}
40+
});
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2015 ArcBees Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package com.gwtplatform.mvp.client.fallback;
18+
19+
import com.google.gwt.core.client.GWT;
20+
import com.google.gwt.core.client.Scheduler;
21+
import com.google.gwt.user.client.ui.HTML;
22+
import com.google.gwt.user.client.ui.RootPanel;
23+
import com.gwtplatform.mvp.client.PreBootstrapper;
24+
25+
public class PreBootstrapperFallback implements PreBootstrapper {
26+
27+
private static final String REASON = "There must have been an issue generating the PreBootstrapper. " +
28+
"Please check your module configuration, ensure there are no compile errors in your source code " +
29+
"and ensure you are not importing sources that cannot be compiled by GWT.";
30+
31+
@Override
32+
public void onPreBootstrap() {
33+
GWT.log(REASON);
34+
35+
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
36+
@Override
37+
public void execute() {
38+
RootPanel.get().add(new HTML("<h3>" + REASON + "</h3>"));
39+
}
40+
});
41+
}
42+
}

gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/rebind/ApplicationControllerGenerator.java

+34-8
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,23 @@
3131
import com.gwtplatform.mvp.client.Bootstrapper;
3232
import com.gwtplatform.mvp.client.DelayedBindRegistry;
3333
import com.gwtplatform.mvp.client.PreBootstrapper;
34+
import com.gwtplatform.mvp.client.fallback.ApplicationControllerFallback;
35+
import com.gwtplatform.mvp.client.fallback.BootstrapperFallback;
36+
import com.gwtplatform.mvp.client.fallback.PreBootstrapperFallback;
3437

3538
/**
3639
* Will generate a {@link com.gwtplatform.mvp.client.ApplicationController}. If the user wants his Generator to be
3740
* generated by GWTP, this Application controller will make sure that the Ginjector is used to trigger the initial
3841
* revealCurrentPlace() from the place manager.
3942
*/
4043
public class ApplicationControllerGenerator extends AbstractGenerator {
44+
private static final String PROBLEM_GENERATING = "There was a problem generating the ApplicationController," +
45+
" this can be caused by bad GWT module configuration or compile errors in your source code.";
4146
private static final String PROPERTY_BOOTSTRAPPER_EMPTY =
4247
"Required configuration property 'gwtp.bootstrapper' can not be empty!.";
4348
private static final String PROPERTY_NOT_FOUND = "Undefined configuration property '%s'.";
44-
private static final String TYPE_NOT_FOUND = "The type '%s' was not found.";
49+
private static final String TYPE_NOT_FOUND = "The type '%s' was not found, either the class name is " +
50+
"wrong or there are compile errors in your code.";
4551
private static final String HINT_URL = "https://github.com/ArcBees/GWTP/wiki/Bootstrapping";
4652
private static final String DOES_NOT_EXTEND_INTERFACE = "'%s' doesn't implement the '%s' interface. See "
4753
+ HINT_URL;
@@ -73,7 +79,6 @@ public String generate(TreeLogger treeLogger, GeneratorContext generatorContext,
7379
return typeName + SUFFIX;
7480
}
7581
try {
76-
7782
JClassType preBootstrapper = getPreBootstrapper();
7883

7984
ClassSourceFileComposerFactory composer = initComposer(preBootstrapper);
@@ -89,6 +94,15 @@ public String generate(TreeLogger treeLogger, GeneratorContext generatorContext,
8994
closeDefinition(sw);
9095

9196
return getPackageName() + "." + getClassName();
97+
} catch (UnableToCompleteException e) {
98+
// Java compile errors can cause problems during compilation
99+
// for tasks like TypeOracle#findType will return null if there
100+
// are compile errors, we should at least hint this possibility.
101+
getTreeLogger().log(TreeLogger.ERROR, PROBLEM_GENERATING);
102+
103+
// Return ApplicationControllerFallback class to avoid
104+
// swallowing the actual compiler issues if there are any.
105+
return ApplicationControllerFallback.class.getName();
92106
} finally {
93107
printWriter.close();
94108
}
@@ -117,12 +131,17 @@ private ClassSourceFileComposerFactory initComposer(JClassType preBootstrapper)
117131
private JClassType getBootstrapper() throws UnableToCompleteException {
118132
String typeName = lookupTypeNameByProperty(PROPERTY_NAME_BOOTSTRAPPER);
119133
if (typeName == null) {
120-
getTreeLogger()
121-
.log(TreeLogger.ERROR, PROPERTY_BOOTSTRAPPER_EMPTY);
122-
throw new UnableToCompleteException();
134+
135+
getTreeLogger().log(TreeLogger.ERROR, PROPERTY_BOOTSTRAPPER_EMPTY);
123136
}
124137

125-
return findAndVerifyType(typeName, Bootstrapper.class);
138+
JClassType type;
139+
try {
140+
type = findAndVerifyType(typeName, Bootstrapper.class);
141+
} catch (UnableToCompleteException ex) {
142+
type = findAndVerifyType(typeName, BootstrapperFallback.class);
143+
}
144+
return type;
126145
}
127146

128147
/**
@@ -134,7 +153,13 @@ private JClassType getPreBootstrapper() throws UnableToCompleteException {
134153
return null;
135154
}
136155

137-
return findAndVerifyType(typeName, PreBootstrapper.class);
156+
JClassType type;
157+
try {
158+
type = findAndVerifyType(typeName, PreBootstrapper.class);
159+
} catch (UnableToCompleteException ex) {
160+
type = findAndVerifyType(typeName, PreBootstrapperFallback.class);
161+
}
162+
return type;
138163
}
139164

140165
/**
@@ -162,7 +187,8 @@ private String lookupTypeNameByProperty(String propertyName) throws UnableToComp
162187
/**
163188
* Find the Java type by the given class name and verify that it extends the given interface.
164189
*/
165-
private JClassType findAndVerifyType(String typeName, Class<?> interfaceClass) throws UnableToCompleteException {
190+
private JClassType findAndVerifyType(String typeName, Class<?> interfaceClass)
191+
throws UnableToCompleteException {
166192
JClassType type = getTypeOracle().findType(typeName);
167193
if (type == null) {
168194
getTreeLogger().log(TreeLogger.ERROR, String.format(TYPE_NOT_FOUND, typeName));

pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@
179179
<name>Richard Wallis</name>
180180
<email>[email protected]</email>
181181
</contributor>
182+
<contributor>
183+
<name>Ben Dol</name>
184+
<email>[email protected]</email>
185+
</contributor>
182186
</contributors>
183187

184188
<scm>

0 commit comments

Comments
 (0)