public MavenLoader(final String m2Home) { setMavenHome(m2Home); try { loadMaven(); final ProjectBuilder projectBuilder = new DefaultProjectBuilder(); for (final URL pomUrl : lookupPomFiles()) { info("URL: %s", pomUrl); setMavenProject(projectBuilder.build(new File(pomUrl.getFile()), new DefaultProjectBuildingRequest()).getProject()); // mavenProjectClass.getMethod("setPomFile", new Class[] { File.class }).invoke(mavenProject, new File(pomUrl.getFile())); } } catch (MalformedURLException mue) { mue.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } setDependencyHandler(new MavenDependencyHandler(mavenProject)); }
/** * Workaround for parent class lookupMojo and lookupConfiguredMojo. * @param name the name of the Mojo to lookup * @param pomPath where to find the POM file * @return a configured MSBuild Mojo for testing * @throws Exception if we can't find the Mojo or the POM is malformed */ protected final Mojo lookupConfiguredMojo( String name, String pomPath ) throws Exception { File pom = new File( getClass().getResource( pomPath ).getPath() ); assertTrue( pom.exists() ); // The following 4 lines are simply to get a MavenProject object MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest(); ProjectBuilder projectBuilder = this.lookup( ProjectBuilder.class ); MavenProject mavenProject = projectBuilder.build( pom, buildingRequest ).getProject(); assertNotNull( mavenProject ); // Used lookupMojo as it sets up most of what we need and reads configuration // variables from the poms. // It doesn't set a MavenProject so we have to do that manually // lookupConfiguredMojo doesn't work properly, configuration variables are no expanded // as we expect and it fails to setup a Log. Mojo mojo = lookupMojo( name, pom ); //Mojo mojo = super.lookupConfiguredMojo( mavenProject, name ); assertNotNull( mojo ); setVariableValueToObject( mojo, "mavenProject", mavenProject ); return mojo; }
public List<Dependency> resolveDependenciesFromPOM(File pomFile) throws Exception { PlexusContainer plexus = new PlexusContainer(); List<Dependency> result; try { ProjectBuildingRequest request = getBuildingRequest(plexus); request.setResolveDependencies(true); ProjectBuilder builder = plexus.lookup(ProjectBuilder.class); ProjectBuildingResult build = builder.build(pomFile, request); result = build.getDependencyResolutionResult().getDependencies(); } finally { plexus.shutdown(); } return result; }
private ProjectBuilder getProjectBuilder() { if ( projectBuilder != null ) { return projectBuilder; } try { projectBuilder = container.lookup( ProjectBuilder.class ); } catch ( ComponentLookupException e ) { // Won't happen } return projectBuilder; }
/** * @throws Exception if any */ @Test public void testSomething() throws Exception { File projectBase = getTestFile("src/test/resources/com/vityuk/ginger/maven/"); File pom = new File(projectBase, "pom.xml"); assertNotNull(pom); assertTrue(pom.exists()); MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest(); ProjectBuilder projectBuilder = lookup(ProjectBuilder.class); MavenProject project = projectBuilder.build(pom, buildingRequest).getProject(); MavenGeneratorMojo myMojo = (MavenGeneratorMojo) lookupConfiguredMojo(project, "ginger-generator"); assertNotNull(myMojo); myMojo.execute(); File outputDirectory = new File(myMojo.outputDirectory); File resultFile = new File(outputDirectory, "com/vityuk/ginger/test1/GeneralConstants.java"); assertTrue("GeneralConstants.java is NOT generated", resultFile.exists()); }
/** * replacement for MavenProject.getParent() which has bad long term memory behaviour. We offset it by recalculating/reparsing everything * therefore should not be used lightly! * pass a MavenProject instance and current configuration and other settings will be applied when loading the parent. * @param project * @return null or the parent mavenproject */ public MavenProject loadParentOf(MavenEmbedder embedder, MavenProject project) throws ProjectBuildingException { MavenProject parent = null; ProjectBuilder builder = embedder.lookupComponent(ProjectBuilder.class); MavenExecutionRequest req = embedder.createMavenExecutionRequest(); M2Configuration active = configProvider.getActiveConfiguration(); req.addActiveProfiles(active.getActivatedProfiles()); req.setNoSnapshotUpdates(true); req.setUpdateSnapshots(false); req.setInteractiveMode(false); req.setRecursive(false); req.setOffline(true); //#238800 important to merge, not replace Properties uprops = req.getUserProperties(); uprops.putAll(MavenProjectCache.createUserPropsForProjectLoading(active.getProperties())); req.setUserProperties(uprops); ProjectBuildingRequest request = req.getProjectBuildingRequest(); request.setRemoteRepositories(project.getRemoteArtifactRepositories()); DefaultMaven maven = (DefaultMaven) embedder.lookupComponent(Maven.class); request.setRepositorySession(maven.newRepositorySession(req)); if (project.getParentFile() != null) { parent = builder.build(project.getParentFile(), request).getProject(); } else if (project.getModel().getParent() != null) { parent = builder.build(project.getParentArtifact(), request).getProject(); } //clear the project building request, it references multiple Maven Models via the RepositorySession cache //is not used in maven itself, most likely used by m2e only.. if (parent != null) { parent.setProjectBuildingRequest(null); } MavenEmbedder.normalizePaths(parent); return parent; }
static List<ModelProblem> runMavenValidationImpl(final File pom) { //TODO profiles based on current configuration?? MavenEmbedder embedder = EmbedderFactory.getProjectEmbedder(); MavenExecutionRequest meReq = embedder.createMavenExecutionRequest(); ProjectBuildingRequest req = meReq.getProjectBuildingRequest(); req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1); // currently enables just <reporting> warning req.setLocalRepository(embedder.getLocalRepository()); List<ArtifactRepository> remoteRepos = RepositoryPreferences.getInstance().remoteRepositories(embedder); req.setRemoteRepositories(remoteRepos); req.setRepositorySession(((DefaultMaven) embedder.lookupComponent(Maven.class)).newRepositorySession(meReq)); List<ModelProblem> problems; try { problems = embedder.lookupComponent(ProjectBuilder.class).build(pom, req).getProblems(); } catch (ProjectBuildingException x) { problems = new ArrayList<ModelProblem>(); List<ProjectBuildingResult> results = x.getResults(); if (results != null) { //one code point throwing ProjectBuildingException contains results, for (ProjectBuildingResult result : results) { problems.addAll(result.getProblems()); } } else { // another code point throwing ProjectBuildingException doesn't contain results.. Throwable cause = x.getCause(); if (cause instanceof ModelBuildingException) { problems.addAll(((ModelBuildingException) cause).getProblems()); } } } return problems; }
MavenEmbedder(EmbedderConfiguration configuration) throws ComponentLookupException { embedderConfiguration = configuration; plexus = configuration.getContainer(); this.maven = (DefaultMaven) plexus.lookup(Maven.class); this.projectBuilder = plexus.lookup(ProjectBuilder.class); this.repositorySystem = plexus.lookup(RepositorySystem.class); this.settingsBuilder = plexus.lookup(SettingsBuilder.class); this.populator = plexus.lookup(MavenExecutionRequestPopulator.class); settingsDecrypter = plexus.lookup(SettingsDecrypter.class); }
static List<ModelProblem> runMavenValidationImpl(final File pom) { MavenEmbedder embedder = EmbedderFactory.getProjectEmbedder(); MavenExecutionRequest meReq = embedder.createMavenExecutionRequest(); ProjectBuildingRequest req = meReq.getProjectBuildingRequest(); req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0); // 3.1 currently enables just <reporting> warning, see issue 223562 for details on why it's bad to show. req.setLocalRepository(embedder.getLocalRepository()); List<ArtifactRepository> remoteRepos = RepositoryPreferences.getInstance().remoteRepositories(embedder); req.setRemoteRepositories(remoteRepos); req.setRepositorySession(((DefaultMaven) embedder.lookupComponent(Maven.class)).newRepositorySession(meReq)); List<ModelProblem> problems; try { problems = embedder.lookupComponent(ProjectBuilder.class).build(pom, req).getProblems(); } catch (ProjectBuildingException x) { problems = new ArrayList<ModelProblem>(); List<ProjectBuildingResult> results = x.getResults(); if (results != null) { //one code point throwing ProjectBuildingException contains results, for (ProjectBuildingResult result : results) { problems.addAll(result.getProblems()); } } else { // another code point throwing ProjectBuildingException doesn't contain results.. Throwable cause = x.getCause(); if (cause instanceof ModelBuildingException) { problems.addAll(((ModelBuildingException) cause).getProblems()); } } } List<ModelProblem> toRet = new LinkedList<ModelProblem>(); for (ModelProblem problem : problems) { if(ModelUtils.checkByCLIMavenValidationLevel(problem)) { toRet.add(problem); } } return toRet; }
@SuppressWarnings("unchecked") private DependencyChecker createDependencyEnforcer(final EnforcerRuleHelper enforcerRuleHelper) throws ComponentLookupException, ExpressionEvaluationException { return new DependencyChecker(log, (RepositorySystem) enforcerRuleHelper.getComponent(RepositorySystem.class), (ProjectBuilder) enforcerRuleHelper.getComponent(ProjectBuilder.class), (RepositorySystemSession) enforcerRuleHelper.evaluate("${session.repositorySession}"), exclusions == null ? Collections.emptySet() : new HashSet<>(Arrays.asList(exclusions)), getWhitelistedLicensesSet()); }
private <T extends AbstractGolangMojo> T findMojo(final Class<T> klazz, final String pomName, final String goal) throws Exception { final File pomFile = new File(GolangMojoCfgTest.class.getResource(pomName).toURI()); final MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); final ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest(); final ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class); final MavenProject project = projectBuilder.build(pomFile, buildingRequest).getProject(); return klazz.cast(this.lookupConfiguredMojo(project, goal)); }
protected Mojo lookupMojo(Path pomPath, String goal) throws Exception { File pom = getTestFile(pomPath.toString()); assertTrue(pom.exists()); MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest(); buildingRequest.setRepositorySession(new DefaultRepositorySystemSession()); ProjectBuilder projectBuilder = lookup(ProjectBuilder.class); MavenProject project = projectBuilder.build(pom, buildingRequest).getProject(); return lookupConfiguredMojo(project, goal); }
private ScmRepositoryIndex(MavenSession session, RepositorySystemSession repoSession, ArtifactFactory repositorySystem, ProjectBuilder projectBuilder, Set<org.srcdeps.core.Scm> scms) { super(); this.session = session; this.repoSession = repoSession; this.repositorySystem = repositorySystem; this.projectBuilder = projectBuilder; this.remoteRepos = RepositoryUtils.toRepos(session.getProjectBuildingRequest().getRemoteRepositories()); this.scms = scms; }
private Mojo lookupConfiguredMojo(String goal, File pom) throws Exception { MavenExecutionRequest request = new DefaultMavenExecutionRequest(); request.setBaseDirectory(pom.getParentFile()); ProjectBuildingRequest configuration = request.getProjectBuildingRequest(); // Fix for bug: https://git-wip-us.apache.org/repos/asf?p=maven-plugin-testing.git;a=commit;h=3cd5f47c586499e438a3f9393304ac9d1f9a7f53 configuration.setRepositorySession(new DefaultRepositorySystemSession()); MavenProject project = lookup(ProjectBuilder.class).build(pom, configuration).getProject(); return super.lookupConfiguredMojo(project, goal); }
protected AbstractXmlMojo newMojo( String pDir ) throws Exception { File testPom = new File( new File( getBasedir(), pDir ), "pom.xml" ); MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest(); ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class); MavenProject project = projectBuilder.build(testPom, buildingRequest).getProject(); // final Build build = new Build(); // build.setDirectory( "target" ); // project.setBuild(build); project.getBuild().setDirectory("target"); AbstractXmlMojo vm = (AbstractXmlMojo) lookupConfiguredMojo(project, getGoal()); setVariableValueToObject( vm, "basedir", new File( getBasedir(), pDir ) ); final Log log = new SilentLog(); DefaultResourceManager rm = new DefaultResourceManager(); setVariableValueToObject( rm, "logger", log ); setVariableValueToObject( vm, "locator", rm ); final Map<String, ResourceLoader> resourceLoaders = new HashMap<String, ResourceLoader>(); resourceLoaders.put( "file", new FileResourceLoader() ); resourceLoaders.put( "jar", new JarResourceLoader() ); resourceLoaders.put( "classloader", new ThreadContextClasspathResourceLoader() ); URLResourceLoader url = new URLResourceLoader(); setVariableValueToObject( url, "logger", log ); resourceLoaders.put( "url", url ); setVariableValueToObject( rm, "resourceLoaders", resourceLoaders ); // MavenProjectStub project = new MavenProjectStub() // { // public Build getBuild() // { // return build; // } // }; // setVariableValueToObject( vm, "project", project ); return vm; }
private JBBPGenerateMojo findMojo(final String pomName, final String goal) throws Exception { final File pomFile = new File(this.getClass().getResource(pomName).toURI()); final MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); final ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest(); final ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class); final MavenProject project = projectBuilder.build(pomFile, buildingRequest).getProject(); return (JBBPGenerateMojo) this.lookupConfiguredMojo(project, goal); }
private UPomMojo init(final File config) throws Exception { final MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); final ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest(); final ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class); final MavenProject project = projectBuilder.build(config, buildingRequest).getProject(); final UPomMojo mojo = (UPomMojo) this.lookupConfiguredMojo(project, "upom"); return mojo; }
/** As {@link #lookupConfiguredMojo(MavenProject, String)} but taking the pom file * and creating the {@link MavenProject}. */ protected Mojo lookupConfiguredMojo(File pom, String goal) throws Exception { assertNotNull( pom ); assertTrue( pom.exists() ); ProjectBuildingRequest buildingRequest = newMavenSession().getProjectBuildingRequest(); ProjectBuilder projectBuilder = lookup(ProjectBuilder.class); MavenProject project = projectBuilder.build(pom, buildingRequest).getProject(); return lookupConfiguredMojo(project, goal); }
public void testSensibleSession(MavenSession s) throws Exception { MavenSession ms = newMavenSession(); //((LicenseAuditMojo)mojo).mavenSession; assertNotNull( ms ); assertNotNull( ms.getLocalRepository().getBasedir() ); System.out.println("Basedir: "+ms.getLocalRepository().getBasedir()); // The following artifacts could not be resolved: org.apache.maven:maven-core:jar:2.0.7 RepositorySystem rs = lookup(RepositorySystem.class); assertNotNull( rs ); // check we can access stuff in remote repos // (fails if we don't have proper aether connectors + transforms, // or if we've not "populated" with default remote repos) ArtifactResult art; art = resolveArtifact(rs, ms, "org.apache.maven:maven-core:jar:2.0.7"); System.out.println(art); assertNotNull(art.getArtifact()); // check we avoid this: // [ERROR] Failed to determine Java version for profile java-1.5-detected @ org.apache.commons:commons-parent:22, /Users/alex/.m2/repository/org/apache/commons/commons-parent/22/commons-parent-22.pom, line 909, column 14 art = resolveArtifact(rs, ms, "org.apache.commons:commons-lang3:3.1"); System.out.println(art); assertNotNull(art.getArtifact()); ProjectBuilder projectBuilder = lookup(ProjectBuilder.class); ProjectBuildingResult res = projectBuilder.build(RepositoryUtils.toArtifact(art.getArtifact()), true, ms.getProjectBuildingRequest()); System.out.println(res); if (!res.getProblems().isEmpty()) fail("Problems: "+res.getProblems()); }
public EvoSuiteRunner(Log logger, List<Artifact> artifacts, ProjectBuilder projectBuilder, RepositorySystemSession repoSession) { super(); this.logger = logger; this.artifacts = artifacts; this.projectBuilder = projectBuilder; this.repoSession = repoSession; }
public Maven(World world, RepositorySystem repositorySystem, DefaultRepositorySystemSession repositorySession, ProjectBuilder builder, List<RemoteRepository> remote, List<ArtifactRepository> remoteLegacy) { this.world = world; this.repositorySystem = repositorySystem; this.repositorySession = repositorySession; this.builder = builder; this.remote = remote; this.remoteLegacy = remoteLegacy; }
public static String evaluateEffectivePom(final Maven3ServerEmbedderImpl embedder, @NotNull final File file, @NotNull List<String> activeProfiles) throws RemoteException, MavenServerProcessCanceledException { final MavenExecutionRequest request = embedder.createRequest(file, activeProfiles, Collections.<String>emptyList(), Collections.<String>emptyList()); final StringWriter w = new StringWriter(); embedder.executeWithMavenSession(request, new Runnable() { @Override public void run() { try { // copied from DefaultMavenProjectBuilder.buildWithDependencies ProjectBuilder builder = embedder.getComponent(ProjectBuilder.class); ProjectBuildingResult buildingResult = builder.build(new File(file.getPath()), request.getProjectBuildingRequest()); MavenProject project = buildingResult.getProject(); XMLWriter writer = new PrettyPrintXMLWriter(w, StringUtils.repeat(" ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE)); writeHeader(writer); writeEffectivePom(project, writer); } catch (Exception e) { throw new RuntimeException(e); } } }); return w.toString(); }
private MavenProject getMavenProject(String pomPath) throws Exception { File pom = new File(pomPath); MavenExecutionRequest request = new DefaultMavenExecutionRequest(); request.setPom(pom); ProjectBuildingRequest configuration = request.getProjectBuildingRequest(); return lookup( ProjectBuilder.class ).build( pom, configuration ).getProject(); }
private MavenProject readMavenProject(File basedir, Properties properties) throws Exception { File pom = new File(basedir, "pom.xml"); MavenExecutionRequest request = new DefaultMavenExecutionRequest(); request.setUserProperties(properties); request.setBaseDirectory(basedir); ProjectBuildingRequest configuration = request.getProjectBuildingRequest(); configuration.setRepositorySession(new DefaultRepositorySystemSession()); MavenProject project = mojos.lookup(ProjectBuilder.class).build(pom, configuration).getProject(); Assert.assertNotNull(project); return project; }
protected void setUp() throws Exception { testDirectory = new File( getBasedir(), BASE_POM_DIR ); projectBuilder = (DefaultProjectBuilder) lookup( ProjectBuilder.class ); repositorySystem = lookup( RepositorySystem.class ); }
public ProjectIterable( MavenProject project, ProjectBuilder builder, ProjectBuildingRequest request, boolean includeSelf ) { root = project; final ArrayList<MavenProject> transientList = new ArrayList<>(); if (includeSelf) { transientList.add(project); } addAllProjects(transientList, project, builder, request); projects = ImmutableList.copyOf(transientList); }
private void addAllProjects( final List<MavenProject> projects, final MavenProject project, final ProjectBuilder builder, final ProjectBuildingRequest request ) { final List<String> modules = root.getModules(); File file = project.getFile().getParentFile(); for (String module : modules) { final File moduleFile = new File( new File(file, module), "pom.xml" ); try { final ProjectBuildingResult result = builder.build( moduleFile, request ); if (!result.getProblems().isEmpty()) { X_Log.warn(getClass(), "Problems encountered looking up module ", moduleFile, result.getProblems()); } projects.add(result.getProject()); if (!result.getProject().getModules().isEmpty()) { addAllProjects(projects, result.getProject(), builder, request); } } catch (ProjectBuildingException e) { X_Log.warn(getClass(), "Unable to build module for ", moduleFile); } } }
public MavenProject readMavenProject(Path pom) throws Exception { MavenExecutionRequest request = new DefaultMavenExecutionRequest(); request.setBaseDirectory(pom.getParent().toFile()); ProjectBuildingRequest configuration = request.getProjectBuildingRequest(); configuration.setRepositorySession(new DefaultRepositorySystemSession()); MavenProject project = rule.lookup(ProjectBuilder.class).build(pom.toFile(), configuration).getProject(); Assert.assertNotNull(project); return project; }
/** * As {@link #lookupConfiguredMojo(MavenProject, String)} but taking the pom file * and creating the {@link MavenProject}. */ protected Mojo lookupConfiguredMojo(File pom, String goal) throws Exception { assertNotNull(pom); assertTrue(pom.exists()); ProjectBuildingRequest buildingRequest = newMavenSession().getProjectBuildingRequest(); ProjectBuilder projectBuilder = lookup(ProjectBuilder.class); MavenProject project = projectBuilder.build(pom, buildingRequest).getProject(); return lookupConfiguredMojo(project, goal); }
public ProjectBuilder getProjectBuilder() { return projectBuilder; }
public void setProjectBuilder(ProjectBuilder projectBuilder) { this.projectBuilder = projectBuilder; }
public ProjectBuilder createProjectBuilder() { return new DefaultProjectBuilder(); }
private MavenResult internalResolveProject( File pom, List<String> activeProfiles, List<String> inactiveProfiles, List<ResolutionListener> dependencyTreeResolutionListeners) { MavenExecutionRequest request = newMavenRequest(pom, activeProfiles, inactiveProfiles, Collections.emptyList()); request.setUpdateSnapshots(updateSnapshots); AtomicReference<MavenResult> reference = new AtomicReference<>(); runMavenRequest( request, () -> { try { ProjectBuilder builder = getMavenComponent(ProjectBuilder.class); List<ProjectBuildingResult> resultList = builder.build( Collections.singletonList(pom), false, request.getProjectBuildingRequest()); ProjectBuildingResult result = resultList.get(0); MavenProject mavenProject = result.getProject(); RepositorySystemSession repositorySession = getMavenComponent(LegacySupport.class).getRepositorySession(); if (repositorySession instanceof DefaultRepositorySystemSession) { ((DefaultRepositorySystemSession) repositorySession) .setTransferListener(new ArtifactTransferListener(mavenProgressNotifier)); if (workspaceCache != null) { ((DefaultRepositorySystemSession) repositorySession) .setWorkspaceReader(new MavenWorkspaceReader(workspaceCache)); } } List<Exception> exceptions = new ArrayList<>(); loadExtensions(mavenProject, exceptions); mavenProject.setDependencyArtifacts( mavenProject.createArtifacts(getMavenComponent(ArtifactFactory.class), null, null)); ArtifactResolutionRequest resolutionRequest = new ArtifactResolutionRequest(); resolutionRequest.setArtifact(mavenProject.getArtifact()); resolutionRequest.setRemoteRepositories(mavenProject.getRemoteArtifactRepositories()); resolutionRequest.setArtifactDependencies(mavenProject.getDependencyArtifacts()); resolutionRequest.setListeners(dependencyTreeResolutionListeners); resolutionRequest.setLocalRepository(localRepo); resolutionRequest.setManagedVersionMap(mavenProject.getManagedVersionMap()); resolutionRequest.setResolveTransitively(true); resolutionRequest.setResolveRoot(false); ArtifactResolver resolver = getMavenComponent(ArtifactResolver.class); ArtifactResolutionResult resolve = resolver.resolve(resolutionRequest); mavenProject.setArtifacts(resolve.getArtifacts()); reference.set(new MavenResult(mavenProject, exceptions)); } catch (Exception e) { reference.set(new MavenResult(null, null, Collections.singletonList(e))); } }); return reference.get(); }
public E lookupConfiguredMojo(File pom, String goal, TestDB testDb) throws Exception { // Mojoテストリソースディレクトリのパスをシステムプロパティに設定しておく // System.setProperty("MojoTestRoot", getMojoTestRoot()); // 各DBの接続情報をシステムプロパティへマージする Properties prop = new Properties(); prop.load(new FileInputStream(new File(Thread.currentThread().getContextClassLoader().getResource("jdbc_test.properties").getPath()))); System.getProperties().putAll(prop); // Maven実行リクエスト初期化 MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); // テスト用のsettingファイルで初期化 // File settings = new File(this.getClass().getResource("settings.xml").getPath()); File settings = new File(Thread.currentThread().getContextClassLoader().getResource("settings.xml").getPath()); MavenExecutionRequestPopulator populator = getContainer().lookup(MavenExecutionRequestPopulator.class); MavenSettingsBuilder mb = this.lookup(MavenSettingsBuilder.class); Settings st = mb.buildSettings(settings); populator.populateFromSettings(executionRequest, st); // カレントディレクトリをセット executionRequest.setBaseDirectory(pom.getParentFile()); // プロファイルを指定DBのプロファイルにセット executionRequest.setActiveProfiles(Collections.singletonList(testDb.name())); // ローカルリポジトリオブジェクトのセット String localRepoPath = this.getClass().getResource("testLocalRepo").toURI().toURL().toString(); executionRequest.setLocalRepository(new MavenArtifactRepository(RepositorySystem.DEFAULT_LOCAL_REPO_ID, localRepoPath, new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy())); // 実行プロジェクトを作成 ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest(); DefaultMaven maven = (DefaultMaven) getContainer().lookup(Maven.class); DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) maven .newRepositorySession(executionRequest); repoSession.setOffline(true); buildingRequest.setRepositorySession(repoSession); ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class); MavenProject project = projectBuilder.build(pom, buildingRequest).getProject(); currentMavenExecutionRequest = executionRequest; // 指定ゴールを持つMojoを取得 Mojo mojo = this.lookupConfiguredMojo(project, goal); currentProject = project; return (E) mojo; }
public static Iterable<MavenProject> getAllChildren(MavenProject project, ProjectBuilder builder, ProjectBuildingRequest request) { return getAllChildren(project, builder, request, true); }
public static Iterable<MavenProject> getAllChildren(MavenProject project, ProjectBuilder builder, ProjectBuildingRequest request, boolean includeSelf) { return new ProjectIterable(project, builder, request, includeSelf); }
public ProjectBuilder getBuilder() { return builder; }