List of usage examples for org.apache.maven.execution MavenExecutionRequest getLoggingLevel
int getLoggingLevel();
From source file:com.ccoe.build.profiler.lifecycle.MavenLifecycleProfiler.java
License:Apache License
@Override public void onEvent(Object event) throws Exception { if (event instanceof SettingsBuildingRequest) { SettingsBuildingRequest settingBuildingRequest = (SettingsBuildingRequest) event; userSettingFile = settingBuildingRequest.getUserSettingsFile(); globalSettingFile = settingBuildingRequest.getGlobalSettingsFile(); }//w w w. j a v a2 s . c om if (event instanceof MavenExecutionRequest) { MavenExecutionRequest mer = (MavenExecutionRequest) event; debug = (mer.getLoggingLevel() == MavenExecutionRequest.LOGGING_LEVEL_DEBUG); context.getData().put("baseAdd", mer.getBaseDirectory()); } if (event instanceof ExecutionEvent) { ExecutionEvent executionEvent = (ExecutionEvent) event; if (executionEvent.getType() == ExecutionEvent.Type.ProjectDiscoveryStarted) { discoveryProfile = new DiscoveryProfile(context, executionEvent, userSettingFile, globalSettingFile, debug); } else if (executionEvent.getType() == ExecutionEvent.Type.SessionStarted) { sessionProfile = new SessionProfile(context, executionEvent, debug); } else if (executionEvent.getType() == ExecutionEvent.Type.SessionEnded) { projectProfile.addPhaseProfile(phaseProfile); //if can accelerate,we will not generate the dependency file sessionProfile.stop(); discoveryProfile.stop(); OutputRenderer renderer = new OutputRenderer(sessionProfile, discoveryProfile); renderer.renderToScreen(); // renderer.renderToJSON(); } else if (executionEvent.getType() == ExecutionEvent.Type.ProjectStarted) { projectProfile = new ProjectProfile(context, executionEvent.getProject(), executionEvent); } else if (executionEvent.getType() == ExecutionEvent.Type.ProjectSucceeded || executionEvent.getType() == ExecutionEvent.Type.ProjectFailed) { if (phaseProfile != null) phaseProfile.stop(); projectProfile.stop(); sessionProfile.addProjectProfile(projectProfile); } else if (executionEvent.getType() == ExecutionEvent.Type.MojoStarted) { String phase = executionEvent.getMojoExecution().getLifecyclePhase(); if (phaseProfile == null) { phaseProfile = new PhaseProfile(context, phase, executionEvent); } else if (phase == null) { phaseProfile.stop(); projectProfile.addPhaseProfile(phaseProfile); phaseProfile = new PhaseProfile(context, "default", executionEvent); } else if (!phase.equals(phaseProfile.getPhase())) { phaseProfile.stop(); projectProfile.addPhaseProfile(phaseProfile); phaseProfile = new PhaseProfile(context, phase, executionEvent); } mojoProfile = new MojoProfile(context, executionEvent.getMojoExecution(), executionEvent); } else if (executionEvent.getType() == ExecutionEvent.Type.MojoSucceeded || executionEvent.getType() == ExecutionEvent.Type.MojoFailed) { mojoProfile.stop(); phaseProfile.addMojoProfile(mojoProfile); } } }
From source file:com.googlecode.ounit.executor.MavenRunner.java
License:Open Source License
public MavenExecutionResult execute(File baseDirectory, List<String> goals, String outputDirectory) { baseDirectory = baseDirectory.getAbsoluteFile(); File pom = modelProcessor.locatePom(baseDirectory); MavenExecutionRequest request = new DefaultMavenExecutionRequest(); request.setBaseDirectory(baseDirectory).setPom(pom).setExecutionListener(executionListener) .setTransferListener(transferListener).setSystemProperties(systemProperties) //.setUserProperties( userProperties ) .setLoggingLevel(logLevel).setInteractiveMode(false) //.setOffline( true ) .setCacheNotFound(true).setCacheTransferError(false).setGoals(goals); /* Apply base profiles */ for (Profile p : baseProfiles) request.addProfile(p.clone());/* ww w .java2s . co m*/ // TODO: Implement system specific settings.xml file /* Create a build profile to set outputDirectory */ if (outputDirectory != null) { Build b = new Build(); b.setDirectory(outputDirectory); Activation a = new Activation(); a.setActiveByDefault(true); Profile p = new Profile(); p.setId("ounitExecutorCustomOutputDirectoryProfile"); p.setActivation(a); p.setBuild(b); request.addProfile(p); } container.getLoggerManager().setThresholds(request.getLoggingLevel()); MavenExecutionResult r = maven.execute(request); return r; }
From source file:org.universaal.tools.packaging.tool.util.KarafFeaturesGenerator.java
License:Apache License
private boolean generateKarafFeatures(String projectName) { try {//from w ww.jav a 2 s . com IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry(); IFile pomResource = g.getPart(projectName).getFile(IMavenConstants.POM_FILE_NAME); IMavenProjectFacade projectFacade = projectManager.create(pomResource, true, null); String ProjectPath = g.getPart(projectName).getLocation().toString(); IMaven maven = MavenPlugin.getMaven(); if (pomResource != null && projectFacade != null) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceDescription description = workspace.getDescription(); if (EclipsePreferencesConfigurator.local.runMavenEmbedded()) { MavenExecutionRequest request = projectManager.createExecutionRequest(pomResource, projectFacade.getResolverConfiguration(), null); request.setLoggingLevel(EclipsePreferencesConfigurator.local.getLogLevel()); DefaultLogger.getInstance() .log("Preparing to run maven, the log level was:" + request.getLoggingLevel() + " but we increased to " + MavenExecutionRequest.LOGGING_LEVEL_DEBUG); request.setLoggingLevel(LOG_LEVEL); if (request.isOffline() && OFFLINE_MODE) { DefaultLogger.getInstance().log("Maven was configured to work OFFLINE, that is fine"); } else if (OFFLINE_MODE) { DefaultLogger.getInstance().log("Maven was configured to work ONLINE, " + "but we are using it OFFLINE for speed it up"); request.setOffline(true); } ExecutionListener listener = request.getExecutionListener(); if (listener != null) { DefaultLogger.getInstance().log("The following ExecutionListener was set " + listener + " but is going to be replaced"); } else { DefaultLogger.getInstance().log("NO ExecutionListener was set, creating one"); } ConsoleLogger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "MavenLogger"); ExecutionEventLogger execLogger = new ExecutionEventLogger(logger); request.setExecutionListener(execLogger); List<String> goals = new ArrayList<String>(); Properties props = new Properties(); DefaultLogger.getInstance() .log("[Application Packager] - Preparing for Karaf features file generation...", 1); if (!description.isAutoBuilding()) { DefaultLogger.getInstance().log("[Application Packager] - " + projectName + " will be compiled now because autobuilding is off.", 1); goals.add("compiler:compile"); // compile it if autobuilding is off request.setGoals(goals); request.setUserProperties(props); execution_result = maven.execute(request, null); DefaultLogger.getInstance().log("[Application Packager] - Compiling operation ended.", 1); } DefaultLogger.getInstance().log("[Application Packager] - Generating Karaf features file...", 1); goals.clear(); props = new Properties(); goals.add(GROUP_ID + ":" + ARTIFACT_ID + ":" + VERSION + ":" + GOAL_FEATURE); request.setGoals(goals); request.setUserProperties(props); execution_result = maven.execute(request, null); if (execution_result.getExceptions() == null || execution_result.getExceptions().isEmpty()) { DefaultLogger.getInstance() .log("[Application Packager] - Karaf features file generated successfully.", 1); return true; } else { DefaultLogger.getInstance().log( "[Application Packager] - Karaf features file not generated because of errors:", 3); for (int i = 0; i < execution_result.getExceptions().size(); i++) DefaultLogger.getInstance().log("[Application Packager] - " + execution_result.getExceptions().get(i).getMessage(), 1); } } else { int exitLevel = 0; DefaultLogger.getInstance() .log("[Application Packager] - Preparing for Karaf features file generation...", 1); if (!description.isAutoBuilding()) { DefaultLogger.getInstance().log("[Application Packager] - " + projectName + " will be compiled now because autobuilding is off.", 1); exitLevel = ProcessExecutor.runMavenCommand("compiler:compile", ProjectPath); DefaultLogger.getInstance().log("[Application Packager] - Compiling operation ended.", 1); if (exitLevel != 0) { DefaultLogger.getInstance() .log("[WARNING] - Error occurred during compiling operation.", 3); } } DefaultLogger.getInstance().log("[Application Packager] - Generating Karaf features file...", 1); exitLevel = ProcessExecutor.runMavenCommand( GROUP_ID + ":" + ARTIFACT_ID + ":" + VERSION + ":" + GOAL_FEATURE, ProjectPath); if (exitLevel == 0) { DefaultLogger.getInstance() .log("[Application Packager] - Karaf features file generated successfully.", 1); return true; } else { DefaultLogger.getInstance().log( "[Application Packager] - FATAL ERROR!!! Karaf features file not generated because of errors", 4); } } } } catch (Exception ex) { ex.printStackTrace(); } return false; }