Skip to content

Commit

Permalink
Merge pull request #734 from BenDol/bd_appgen
Browse files Browse the repository at this point in the history
Stop swallowing compile errors ApplicationControllerGenerator!
  • Loading branch information
Chris-V committed Oct 19, 2015
2 parents d819285 + d30fa45 commit e001fb5
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2015 ArcBees Inc.
*
* Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
*
* 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.gwtplatform.mvp.client.fallback;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;
import com.gwtplatform.mvp.client.ApplicationController;

public class ApplicationControllerFallback implements ApplicationController {

public static final String REASON = "There must have been an issue generating " +
"the ApplicationController. Please check your module configuration, ensure there " +
"are no compile errors in your source code and ensure you are not importing sources " +
"that cannot be compiled by GWT.";

@Override
public void init() {
GWT.log(REASON);

Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
RootPanel.get().add(new HTML("<h3>" + REASON + "</h3>"));
}
});
}

@Override
public void onModuleLoad() {
init();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2015 ArcBees Inc.
*
* Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
*
* 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.gwtplatform.mvp.client.fallback;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;
import com.gwtplatform.mvp.client.Bootstrapper;

public class BootstrapperFallback implements Bootstrapper {

private static final String REASON = "There must have been an issue generating the Bootstrapper. " +
"Please check your module configuration, ensure there are no compile errors in your source code " +
"and ensure you are not importing sources that cannot be compiled by GWT.";

@Override
public void onBootstrap() {
GWT.log(REASON);

Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
RootPanel.get().add(new HTML("<h3>" + REASON + "</h3>"));
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2015 ArcBees Inc.
*
* Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
*
* 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.gwtplatform.mvp.client.fallback;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;
import com.gwtplatform.mvp.client.PreBootstrapper;

public class PreBootstrapperFallback implements PreBootstrapper {

private static final String REASON = "There must have been an issue generating the PreBootstrapper. " +
"Please check your module configuration, ensure there are no compile errors in your source code " +
"and ensure you are not importing sources that cannot be compiled by GWT.";

@Override
public void onPreBootstrap() {
GWT.log(REASON);

Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
RootPanel.get().add(new HTML("<h3>" + REASON + "</h3>"));
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,23 @@
import com.gwtplatform.mvp.client.Bootstrapper;
import com.gwtplatform.mvp.client.DelayedBindRegistry;
import com.gwtplatform.mvp.client.PreBootstrapper;
import com.gwtplatform.mvp.client.fallback.ApplicationControllerFallback;
import com.gwtplatform.mvp.client.fallback.BootstrapperFallback;
import com.gwtplatform.mvp.client.fallback.PreBootstrapperFallback;

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

JClassType preBootstrapper = getPreBootstrapper();

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

return getPackageName() + "." + getClassName();
} catch (UnableToCompleteException e) {
// Java compile errors can cause problems during compilation
// for tasks like TypeOracle#findType will return null if there
// are compile errors, we should at least hint this possibility.
getTreeLogger().log(TreeLogger.ERROR, PROBLEM_GENERATING);

// Return ApplicationControllerFallback class to avoid
// swallowing the actual compiler issues if there are any.
return ApplicationControllerFallback.class.getName();
} finally {
printWriter.close();
}
Expand Down Expand Up @@ -117,12 +131,17 @@ private ClassSourceFileComposerFactory initComposer(JClassType preBootstrapper)
private JClassType getBootstrapper() throws UnableToCompleteException {
String typeName = lookupTypeNameByProperty(PROPERTY_NAME_BOOTSTRAPPER);
if (typeName == null) {
getTreeLogger()
.log(TreeLogger.ERROR, PROPERTY_BOOTSTRAPPER_EMPTY);
throw new UnableToCompleteException();

getTreeLogger().log(TreeLogger.ERROR, PROPERTY_BOOTSTRAPPER_EMPTY);
}

return findAndVerifyType(typeName, Bootstrapper.class);
JClassType type;
try {
type = findAndVerifyType(typeName, Bootstrapper.class);
} catch (UnableToCompleteException ex) {
type = findAndVerifyType(typeName, BootstrapperFallback.class);
}
return type;
}

/**
Expand All @@ -134,7 +153,13 @@ private JClassType getPreBootstrapper() throws UnableToCompleteException {
return null;
}

return findAndVerifyType(typeName, PreBootstrapper.class);
JClassType type;
try {
type = findAndVerifyType(typeName, PreBootstrapper.class);
} catch (UnableToCompleteException ex) {
type = findAndVerifyType(typeName, PreBootstrapperFallback.class);
}
return type;
}

/**
Expand Down Expand Up @@ -162,7 +187,8 @@ private String lookupTypeNameByProperty(String propertyName) throws UnableToComp
/**
* Find the Java type by the given class name and verify that it extends the given interface.
*/
private JClassType findAndVerifyType(String typeName, Class<?> interfaceClass) throws UnableToCompleteException {
private JClassType findAndVerifyType(String typeName, Class<?> interfaceClass)
throws UnableToCompleteException {
JClassType type = getTypeOracle().findType(typeName);
if (type == null) {
getTreeLogger().log(TreeLogger.ERROR, String.format(TYPE_NOT_FOUND, typeName));
Expand Down
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@
<name>Richard Wallis</name>
<email>rdwallis@gmail.com</email>
</contributor>
<contributor>
<name>Ben Dol</name>
<email>dolb90@gmail.com</email>
</contributor>
</contributors>

<scm>
Expand Down

0 comments on commit e001fb5

Please sign in to comment.