use of org.apache.maven.execution.ExecutionEvent.Type in project pom-manipulation-ext by release-engineering.
the class ManipulatingEventSpy method onEvent.
@Override
public void onEvent(final Object event) throws Exception {
boolean required = false;
try {
if (event instanceof ExecutionEvent) {
final ExecutionEvent ee = (ExecutionEvent) event;
required = Boolean.parseBoolean(ee.getSession().getRequest().getUserProperties().getProperty(REQUIRE_EXTENSION, "false"));
final ExecutionEvent.Type type = ee.getType();
if (type == Type.ProjectDiscoveryStarted) {
if (ee.getSession() != null) {
if (ee.getSession().getRequest().getLoggingLevel() == 0) {
final ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
root.setLevel(Level.DEBUG);
}
session.setMavenSession(ee.getSession());
if (ee.getSession().getRequest().getPom() != null) {
Properties config = configIO.parse(ee.getSession().getRequest().getPom().getParentFile());
String value = session.getUserProperties().getProperty("allowConfigFilePrecedence");
if (isNotEmpty(value) && "true".equalsIgnoreCase(value)) {
session.getUserProperties().putAll(config);
} else {
for (String key : config.stringPropertyNames()) {
if (!session.getUserProperties().containsKey(key)) {
session.getUserProperties().setProperty(key, config.getProperty(key));
}
}
}
}
manipulationManager.init(session);
} else {
logger.error("Null session ; unable to continue");
return;
}
if (!session.isEnabled()) {
logger.info("Manipulation engine disabled via command-line option");
return;
} else if (ee.getSession().getRequest().getPom() == null) {
logger.info("Manipulation engine disabled. No project found.");
return;
} else if (new File(ee.getSession().getRequest().getPom().getParentFile(), ManipulationManager.MARKER_FILE).exists()) {
logger.info("Skipping manipulation as previous execution found.");
return;
}
manipulationManager.scanAndApply(session);
}
}
} catch (final ManipulationException e) {
logger.error("Extension failure", e);
if (required) {
throw e;
} else {
session.setError(e);
}
}// Catch any runtime exceptions and mark them to fail the build as well.
catch (final RuntimeException e) {
logger.error("Extension failure", e);
if (required) {
throw e;
} else {
session.setError(new ManipulationException("Caught runtime exception", e));
}
} finally {
super.onEvent(event);
}
}
Aggregations