org.apache.maven.execution.MavenSession Java Examples
The following examples show how to use
org.apache.maven.execution.MavenSession.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MojoExecutor.java From dew with Apache License 2.0 | 6 votes |
public void execute( MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex ) throws LifecycleExecutionException { if (SkipCheck.skip(session.getCurrentProject().getBasedir()) && mojoExecutions.stream().map(MojoExecution::getGoal).map(String::toLowerCase) .anyMatch(s -> s.contains("group.idealworld.dew:dew-maven-plugin:release") || s.contains("dew:release") || s.contains("deploy"))) { return; } DependencyContext dependencyContext = newDependencyContext( session, mojoExecutions ); PhaseRecorder phaseRecorder = new PhaseRecorder( session.getCurrentProject() ); for ( MojoExecution mojoExecution : mojoExecutions ) { execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); } }
Example #2
Source File: MojoExecutor.java From heroku-maven-plugin with MIT License | 6 votes |
public static Path createDependencyListFile(MavenProject mavenProject, MavenSession mavenSession, BuildPluginManager pluginManager) throws MojoExecutionException, IOException { Path path = Files.createTempFile("heroku-maven-plugin", "mvn-dependency-list.log"); executeMojo( plugin( groupId("org.apache.maven.plugins"), artifactId("maven-dependency-plugin"), version("2.4") ), goal("list"), configuration( element(name("outputFile"), path.toString()) ), executionEnvironment( mavenProject, mavenSession, pluginManager ) ); return path; }
Example #3
Source File: WatchersTest.java From wisdom with Apache License 2.0 | 6 votes |
@Test public void testWatchers() { Properties properties = new Properties(); MavenSession session = mock(MavenSession.class); when(session.getExecutionProperties()).thenReturn(properties); // Nothing added. assertThat(Watchers.all(session)).isEmpty(); // Added watchers. Watcher watcher1 = mock(Watcher.class); Watchers.add(session, watcher1); assertThat(Watchers.all(session)).hasSize(1); Watcher watcher2 = mock(Watcher.class); Watchers.add(session, watcher2); assertThat(Watchers.all(session)).hasSize(2); // Remove watchers assertThat(Watchers.remove(session, watcher1)).isTrue(); assertThat(Watchers.remove(session, null)).isFalse(); assertThat(Watchers.all(session)).hasSize(1); }
Example #4
Source File: MavenProjectConfigCollector.java From helidon-build-tools with Apache License 2.0 | 6 votes |
@Override public void afterProjectsRead(MavenSession session) { if (ENABLED) { // Init state supportedProjectDir = null; projectConfig = null; debug("collector enabled"); try { // Ensure that we support this project supportedProjectDir = assertSupportedProject(session); // Install our listener so we can know if compilation occurred and succeeded final MavenExecutionRequest request = session.getRequest(); request.setExecutionListener(new EventListener(request.getExecutionListener())); } catch (IllegalStateException e) { supportedProjectDir = null; } } else { debug("collector disabled"); } }
Example #5
Source File: BuildMojoTest.java From docker-maven-plugin with Apache License 2.0 | 6 votes |
private BuildMojo setupMojo(final File pom) throws Exception { final MavenProject project = new ProjectStub(pom); final MavenSession session = newMavenSession(project); // for some reason the superclass method newMavenSession() does not copy properties from the // project model to the session. This is needed for the use of ExpressionEvaluator in BuildMojo. session.getRequest().setUserProperties(project.getModel().getProperties()); final MojoExecution execution = newMojoExecution("build"); final BuildMojo mojo = (BuildMojo) this.lookupConfiguredMojo(session, execution); mojo.buildDirectory = "target"; // Because test poms are loaded from test/resources, tagInfoFile will default to // test/resources/target/image_info.json. Writing the json file to that location will fail // because target doesn't exist. So force it to use project's target directory. // But don't overwrite it if a test sets a non-default value. if (mojo.tagInfoFile.contains("src/test/resources")) { mojo.tagInfoFile = "target/image_info.json"; } mojo.session = session; mojo.execution = execution; return mojo; }
Example #6
Source File: SmartTestingMavenConfigurer.java From smart-testing with Apache License 2.0 | 6 votes |
@Override public void afterProjectsRead(MavenSession session) throws MavenExecutionException { Log.setLoggerFactory(new MavenExtensionLoggerFactory(mavenLogger)); loadConfigAndCheckIfInstallationShouldBeSkipped(session); if (skipExtensionInstallation) { return; } logger.debug("Version: %s", ExtensionVersion.version().toString()); logger.debug("Applied user properties: %s", session.getUserProperties()); File projectDirectory = session.getTopLevelProject().getModel().getProjectDirectory(); logger.info("Enabling extension."); configureExtension(session, configuration); calculateChanges(projectDirectory, configuration); Runtime.getRuntime().addShutdownHook(new Thread(() -> purgeLocalStorageAndExportPom(session))); }
Example #7
Source File: SmartTestingMavenConfigurer.java From smart-testing with Apache License 2.0 | 6 votes |
private void loadConfigAndCheckIfInstallationShouldBeSkipped(MavenSession session) { SkipInstallationChecker skipInstallationChecker = new SkipInstallationChecker(session); skipExtensionInstallation = skipInstallationChecker.shouldSkip(); if (skipExtensionInstallation) { logExtensionDisableReason(Log.getLogger(), skipInstallationChecker.getReason()); return; } File executionRootDirectory = new File(session.getExecutionRootDirectory()); configuration = ConfigurationLoader.load(executionRootDirectory, this::isProjectRootDirectory); Log.setLoggerFactory(new MavenExtensionLoggerFactory(mavenLogger, configuration)); logger = Log.getLogger(); if (skipInstallationChecker.shouldSkipForConfiguration(configuration)) { skipExtensionInstallation = true; logExtensionDisableReason(logger, skipInstallationChecker.getReason()); } }
Example #8
Source File: MojoExecutor.java From heroku-maven-plugin with MIT License | 6 votes |
public static void copyDependenciesToBuildDirectory(MavenProject mavenProject, MavenSession mavenSession, BuildPluginManager pluginManager) throws MojoExecutionException { executeMojo( plugin( groupId("org.apache.maven.plugins"), artifactId("maven-dependency-plugin"), version("2.4") ), goal("copy-dependencies"), configuration( element(name("outputDirectory"), "${project.build.directory}/dependency") ), executionEnvironment( mavenProject, mavenSession, pluginManager ) ); }
Example #9
Source File: CompileJdtClasspathVisibilityTest.java From takari-lifecycle with Eclipse Public License 1.0 | 6 votes |
@Test public void testReference_testCompile() throws Exception { File basedir = resources.getBasedir("compile-jdt-classpath-visibility/reference"); MavenProject project = mojos.readMavenProject(basedir); addDependency(project, "dependency", DEPENDENCY); MavenSession session = mojos.newMavenSession(project); Xpp3Dom[] params = new Xpp3Dom[] {param("compilerId", "jdt"), // param("transitiveDependencyReference", "error"), // param("privatePackageReference", "error")}; mojos.executeMojo(session, project, "compile", params); mojos.executeMojo(session, project, "testCompile", params); }
Example #10
Source File: CompileTest.java From takari-lifecycle with Eclipse Public License 1.0 | 6 votes |
@Test public void testImplicitClassfileGeneration() throws Exception { // javac automatically generates class files from sources found on classpath in some cases // the point of this test is to make sure this behaviour is disabled File dependency = compile("compile/basic"); cp(dependency, "src/main/java/basic/Basic.java", "target/classes/basic/Basic.java"); touch(dependency, "target/classes/basic/Basic.java"); // must be newer than .class file File basedir = resources.getBasedir("compile/implicit-classfile"); MavenProject project = mojos.readMavenProject(basedir); MavenSession session = mojos.newMavenSession(project); MojoExecution execution = mojos.newMojoExecution(); addDependency(project, "dependency", new File(dependency, "target/classes")); mojos.executeMojo(session, project, execution); mojos.assertBuildOutputs(new File(basedir, "target/classes"), "implicit/Implicit.class"); }
Example #11
Source File: SmartBuilderImpl.java From takari-smart-builder with Apache License 2.0 | 6 votes |
SmartBuilderImpl(LifecycleModuleBuilder lifecycleModuleBuilder, MavenSession session, ReactorContext reactorContext, TaskSegment taskSegment, Set<MavenProject> projects) { this.lifecycleModuleBuilder = lifecycleModuleBuilder; this.rootSession = session; this.reactorContext = reactorContext; this.taskSegment = taskSegment; this.degreeOfConcurrency = Integer.valueOf(session.getRequest().getDegreeOfConcurrency()); final Comparator<MavenProject> projectComparator = ProjectComparator.create(session); this.reactorBuildQueue = new ReactorBuildQueue(projects, session.getProjectDependencyGraph()); this.executor = new ProjectExecutorService(degreeOfConcurrency, projectComparator); this.stats = ReactorBuildStats.create(projects); }
Example #12
Source File: MappingTrackArchiver.java From docker-maven-plugin with Apache License 2.0 | 6 votes |
private File getLocalMavenRepoFile(MavenSession session, File source) { ArtifactRepository localRepo = session.getLocalRepository(); if (localRepo == null) { log.warn("No local repo found so not adding any extra watches in the local repository"); return null; } Artifact artifact = getArtifactFromJar(source); if (artifact != null) { try { return new File(localRepo.getBasedir(), localRepo.pathOf(artifact)); } catch (InvalidArtifactRTException e) { log.warn("Cannot get the local repository path for %s in base dir %s : %s", artifact, localRepo.getBasedir(), e.getMessage()); } } return null; }
Example #13
Source File: ChangeDetector.java From spring-cloud-contract with Apache License 2.0 | 6 votes |
static boolean inputFilesChangeDetected(File contractsDirectory, MojoExecution mojoExecution, MavenSession session) throws MojoExecutionException { IncrementalBuildHelper incrementalBuildHelper = new IncrementalBuildHelper( mojoExecution, session); DirectoryScanner scanner = incrementalBuildHelper.getDirectoryScanner(); scanner.setBasedir(contractsDirectory); scanner.scan(); boolean changeDetected = incrementalBuildHelper.inputFileTreeChanged(scanner); if (scanner.getIncludedFiles().length == 0) { // at least one input file must exist to consider changed/unchanged // return true to skip incremental build and make visible no input file at all return true; } return changeDetected; }
Example #14
Source File: TestPropertiesMojoTest.java From takari-lifecycle with Eclipse Public License 1.0 | 6 votes |
@Test public void testClasspathScope() throws Exception { File basedir = resources.getBasedir(); MavenProject project = mojos.readMavenProject(basedir); MavenSession session = mojos.newMavenSession(project); File providedScoped = temp.newFile("provided.jar").getCanonicalFile(); File testScoped = temp.newFile("test.jar").getCanonicalFile(); mojos.newDependency(providedScoped).setGroupId("g").setArtifactId("provided").setScope("provided").addTo(project); mojos.newDependency(testScoped).setGroupId("g").setArtifactId("test").setScope("test").addTo(project); mojos.executeMojo(session, project, "testProperties"); Map<String, String> properties = readProperties(basedir); Assert.assertEquals(new File(basedir, "target/classes").getCanonicalPath(), properties.get("classpath")); }
Example #15
Source File: CliTest.java From pom-manipulation-ext with Apache License 2.0 | 6 votes |
@Test public void checkLocalRepositoryWithDefaults() throws Exception { Cli c = new Cli(); File settings = writeSettings( temp.newFile()); TestUtils.executeMethod( c, "run", new Object[] { new String[] { "-s", settings.toString()} } ); ManipulationSession session = (ManipulationSession) FieldUtils.readField( c, "session", true ); MavenSession ms = (MavenSession)FieldUtils.readField( session, "mavenSession", true ); assertEquals( ms.getRequest().getLocalRepository().getBasedir(), ms.getRequest().getLocalRepositoryPath().toString() ); assertEquals( "File " + new File( ms.getRequest().getLocalRepository().getBasedir() ).getParentFile().toString() + " was not equal to " + System.getProperty( "user.home" ) + File.separatorChar + ".m2", new File( ms.getRequest().getLocalRepository().getBasedir() ).getParentFile().toString(), System.getProperty( "user.home" ) + File.separatorChar + ".m2" ); }
Example #16
Source File: PropertiesUtilsTest.java From pom-manipulation-ext with Apache License 2.0 | 6 votes |
@SuppressWarnings( "deprecation" ) private ManipulationSession createUpdateSession() throws Exception { ManipulationSession session = new ManipulationSession(); session.setState( new DependencyState( p ) ); session.setState( new VersioningState( p ) ); session.setState( new CommonState( p ) ); final MavenExecutionRequest req = new DefaultMavenExecutionRequest().setUserProperties( p ).setRemoteRepositories( Collections.emptyList() ); final PlexusContainer container = new DefaultPlexusContainer(); final MavenSession mavenSession = new MavenSession( container, null, req, new DefaultMavenExecutionResult() ); session.setMavenSession( mavenSession ); return session; }
Example #17
Source File: MojoExecutor.java From dew with Apache License 2.0 | 6 votes |
public void execute( MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex ) throws LifecycleExecutionException { if (SkipCheck.skip(session.getCurrentProject().getBasedir()) && mojoExecutions.stream().map(MojoExecution::getGoal).map(String::toLowerCase) .anyMatch(s -> s.contains("group.idealworld.dew:dew-maven-plugin:release") || s.contains("dew:release") || s.contains("deploy"))) { return; } DependencyContext dependencyContext = newDependencyContext( session, mojoExecutions ); PhaseRecorder phaseRecorder = new PhaseRecorder( session.getCurrentProject() ); for ( MojoExecution mojoExecution : mojoExecutions ) { execute( session, mojoExecution, projectIndex, dependencyContext, phaseRecorder ); } }
Example #18
Source File: MojoExecutor.java From dew with Apache License 2.0 | 5 votes |
public DependencyContext newDependencyContext( MavenSession session, List<MojoExecution> mojoExecutions ) { Set<String> scopesToCollect = new TreeSet<>(); Set<String> scopesToResolve = new TreeSet<>(); collectDependencyRequirements( scopesToResolve, scopesToCollect, mojoExecutions ); return new DependencyContext( session.getCurrentProject(), scopesToCollect, scopesToResolve ); }
Example #19
Source File: TestPropertiesMojoTest.java From takari-lifecycle with Eclipse Public License 1.0 | 5 votes |
@Test public void testOffline() throws Exception { File basedir = resources.getBasedir("testproperties/basic"); MavenProject project = mojos.readMavenProject(basedir); MavenSession session = mojos.newMavenSession(project); session.getRequest().setOffline(true); mojos.executeMojo(session, project, newMojoExecution()); Assert.assertEquals("true", readProperties(basedir).get("offline")); session.getRequest().setOffline(false); mojos.executeMojo(session, project, newMojoExecution()); Assert.assertEquals("false", readProperties(basedir).get("offline")); }
Example #20
Source File: PropertyConfigHandler.java From docker-maven-plugin with Apache License 2.0 | 5 votes |
@Override public List<ImageConfiguration> resolve(ImageConfiguration fromConfig, MavenProject project, MavenSession session) throws IllegalArgumentException { Map<String, String> externalConfig = fromConfig.getExternalConfig(); String prefix = getPrefix(externalConfig); Properties properties = EnvUtil.getPropertiesWithSystemOverrides(project); PropertyMode propertyMode = getMode(externalConfig); ValueProvider valueProvider = new ValueProvider(prefix, properties, propertyMode); RunImageConfiguration run = extractRunConfiguration(fromConfig, valueProvider); BuildImageConfiguration build = extractBuildConfiguration(fromConfig, valueProvider, project); WatchImageConfiguration watch = extractWatchConfig(fromConfig, valueProvider); String name = valueProvider.getString(NAME, fromConfig.getName()); String alias = valueProvider.getString(ALIAS, fromConfig.getAlias()); String removeNamePattern = valueProvider.getString(REMOVE_NAME_PATTERN, fromConfig.getRemoveNamePattern()); String stopNamePattern = valueProvider.getString(STOP_NAME_PATTERN, fromConfig.getStopNamePattern()); if (name == null) { throw new IllegalArgumentException(String.format("Mandatory property [%s] is not defined", NAME)); } return Collections.singletonList( new ImageConfiguration.Builder() .name(name) .alias(alias) .removeNamePattern(removeNamePattern) .stopNamePattern(stopNamePattern) .runConfig(run) .buildConfig(build) .watchConfig(watch) .build()); }
Example #21
Source File: SkipInstallationCheckerTest.java From smart-testing with Apache License 2.0 | 5 votes |
@Test public void checker_should_return_false_when_package_in_default_goal_is_set_set() { // given MavenSession mavenSession = setUpMavenSession(Collections.emptyList(), "clean package"); // when SkipInstallationChecker skipInstallationChecker = new SkipInstallationChecker(mavenSession); // then softly.assertThat(skipInstallationChecker).isSkipped(false); }
Example #22
Source File: SkipInstallationCheckerTest.java From smart-testing with Apache License 2.0 | 5 votes |
@Test public void checker_should_return_true_when_clean_goal_is_set() { // given MavenSession mavenSession = setUpMavenSession(Collections.singletonList("clean"), null); // when SkipInstallationChecker skipInstallationChecker = new SkipInstallationChecker(mavenSession); // then softly.assertThat(skipInstallationChecker) .isSkipped(true) .forReason(NO_TEST_GOAL_REASON); }
Example #23
Source File: DeployProcess.java From dew with Apache License 2.0 | 5 votes |
public static void process(MavenProject mavenProject, MavenSession mavenSession, BuildPluginManager pluginManager, File output) { log.info("Deploy SDK from : {}", output.getPath()); MavenHelper.invoke("org.apache.maven.plugins", "maven-invoker-plugin", null, "run", new HashMap<>() { { put("projectsDirectory", output.getParent()); put("goals", new HashMap<>() { { put("goal", "-P release"); } }); put("mavenOpts", ""); } }, mavenProject, mavenSession, pluginManager); }
Example #24
Source File: CompileJdtClasspathVisibilityTest.java From takari-lifecycle with Eclipse Public License 1.0 | 5 votes |
@Test public void testReference_accessRulesViolationIgnore() throws Exception { File basedir = resources.getBasedir("compile-jdt-classpath-visibility/reference"); MavenProject project = mojos.readMavenProject(basedir); addDependency(project, "dependency", DEPENDENCY); MavenSession session = mojos.newMavenSession(project); mojos.executeMojo(session, project, "compile", // param("compilerId", "jdt"), // param("transitiveDependencyReference", "ignore"), // param("privatePackageReference", "ignore")); }
Example #25
Source File: MojoExecutor.java From dew with Apache License 2.0 | 5 votes |
public void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex, DependencyContext dependencyContext, PhaseRecorder phaseRecorder ) throws LifecycleExecutionException { execute( session, mojoExecution, projectIndex, dependencyContext ); phaseRecorder.observeExecution( mojoExecution ); }
Example #26
Source File: MojoExecutor.java From dew with Apache License 2.0 | 5 votes |
public DependencyContext newDependencyContext( MavenSession session, List<MojoExecution> mojoExecutions ) { Set<String> scopesToCollect = new TreeSet<>(); Set<String> scopesToResolve = new TreeSet<>(); collectDependencyRequirements( scopesToResolve, scopesToCollect, mojoExecutions ); return new DependencyContext( session.getCurrentProject(), scopesToCollect, scopesToResolve ); }
Example #27
Source File: SmartTestingMavenConfigurer.java From smart-testing with Apache License 2.0 | 5 votes |
@Override public void afterSessionEnd(MavenSession session) throws MavenExecutionException { if (skipExtensionInstallation) { return; } if (!configuration.areStrategiesDefined()) { logStrategiesNotDefined(); } purgeLocalStorageAndExportPom(session); }
Example #28
Source File: MojoExecutor.java From dew with Apache License 2.0 | 5 votes |
public void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex, DependencyContext dependencyContext, PhaseRecorder phaseRecorder ) throws LifecycleExecutionException { execute( session, mojoExecution, projectIndex, dependencyContext ); phaseRecorder.observeExecution( mojoExecution ); }
Example #29
Source File: MojoParameters.java From jkube with Eclipse Public License 2.0 | 5 votes |
public MojoParameters(MavenSession session, MavenProject project, MavenArchiveConfiguration archive, MavenFileFilter mavenFileFilter, MavenReaderFilter mavenFilterReader, Settings settings, String sourceDirectory, String outputDirectory, List<MavenProject> reactorProjects) { this.archive = archive; this.session = session; this.mavenFileFilter = mavenFileFilter; this.mavenFilterReader = mavenFilterReader; this.project = project; this.settings = settings; this.sourceDirectory = sourceDirectory; this.outputDirectory = outputDirectory; this.reactorProjects = reactorProjects; }
Example #30
Source File: MavenHelper.java From dew with Apache License 2.0 | 5 votes |
/** * 调用指定的Maven mojo. * * @param groupId the group id * @param artifactId the artifact id * @param version the version * @param goal the goal * @param configuration the configuration * @param mavenProject the maven project * @param mavenSession the maven session * @param mavenPluginManager the maven plugin manager */ @SneakyThrows public static void invoke(String groupId, String artifactId, String version, String goal, Map<String, Object> configuration, MavenProject mavenProject, MavenSession mavenSession, BuildPluginManager mavenPluginManager ) { log.debug("invoke groupId = " + groupId + " ,artifactId = " + artifactId + " ,version = " + version); List<Element> config = configuration.entrySet().stream() .map(item -> { if (item.getValue() instanceof Map<?, ?>) { var eles = ((Map<?, ?>) item.getValue()).entrySet().stream() .map(subItem -> element(subItem.getKey().toString(), subItem.getValue().toString())) .collect(Collectors.toList()); return element(item.getKey(), eles.toArray(new MojoExecutor.Element[eles.size()])); } else { return element(item.getKey(), item.getValue().toString()); } }) .collect(Collectors.toList()); org.apache.maven.model.Plugin plugin; if (version == null) { plugin = plugin(groupId, artifactId); } else { plugin = plugin(groupId, artifactId, version); } executeMojo( plugin, goal(goal), configuration(config.toArray(new Element[]{})), executionEnvironment( mavenProject, mavenSession, mavenPluginManager ) ); }