static AgentDependencies init(PluginDescriptor pluginDescriptor) throws MojoExecutionException { String pluginGroupId = pluginDescriptor.getGroupId(); String pluginArtifactId = pluginDescriptor.getArtifactId(); List<ExpectedDependency> expectedDependencies = Arrays.asList( new ExpectedDependency(pluginGroupId, "promagent-agent"), new ExpectedDependency(pluginGroupId, "promagent-internal"), new ExpectedDependency(pluginGroupId, "promagent-api"), new ExpectedDependency("io.prometheus", "simpleclient_common"), new ExpectedDependency("io.prometheus", "simpleclient"), new ExpectedDependency("net.bytebuddy", "byte-buddy"), new ExpectedDependency("commons-io", "commons-io") ); List<Artifact> actualDependencies = resolveVersions(pluginDescriptor, pluginArtifactId, expectedDependencies); failUnlessComplete(actualDependencies, expectedDependencies, pluginArtifactId); return new AgentDependencies(pluginGroupId, actualDependencies); }
public static InputStream getWorkflowDescriptor(String goalName, PluginDescriptor pluginDescriptor, Optional<File> customWorkflowDescriptor, Logger log) throws MojoExecutionException { log.info("Constructing workflow for processing"); String goalPrefix = pluginDescriptor.getGoalPrefix(); if (customWorkflowDescriptor.isPresent()) { File customDescriptor = customWorkflowDescriptor.get(); log.debug("Requested overriding of workflow with file: " + customDescriptor.getAbsolutePath()); if (customDescriptor.exists() && customDescriptor.isFile()) { try { log.info("Workflow of goal '" + goalPrefix + ':' + goalName + "' will be overriden by file '" + customDescriptor.getAbsolutePath() + "'."); return new FileInputStream(customDescriptor); } catch (Exception e) { throw new MojoExecutionException("Unable to load custom workflow for goal " + goalName, e); } } else { throw new MojoExecutionException("Unable to load custom workflow for goal " + goalPrefix + ':' + goalName + ". The workflow file '" + customDescriptor.getAbsolutePath() + "' does not exist!"); } } log.info("Goal '" + goalPrefix + ':' + goalName + "' will use default workflow packaged with the plugin."); return Thread.currentThread().getContextClassLoader().getResourceAsStream(DEFAULT_WORKFLOW_DIR + "/" + goalName); }
private void executePluginDef(InputStream is) throws Exception { Xpp3Dom pluginDef = Xpp3DomBuilder.build(is, "utf-8"); Plugin plugin = loadPlugin(pluginDef); Xpp3Dom config = pluginDef.getChild("configuration"); PluginDescriptor pluginDesc = pluginManager.loadPlugin(plugin, mavenProject.getRemotePluginRepositories(), mavenSession.getRepositorySession()); Xpp3Dom executions = pluginDef.getChild("executions"); for ( Xpp3Dom execution : executions.getChildren()) { Xpp3Dom goals = execution.getChild("goals"); for (Xpp3Dom goal : goals.getChildren()) { MojoDescriptor desc = pluginDesc.getMojo(goal.getValue()); pluginManager.executeMojo(mavenSession, new MojoExecution(desc, config)); } } }
/** */ public PlanContext( ProcessRunner processRunner, PluginDescriptor pluginDescriptor, BuildContext buildContext, Log log, SrcfilesDirs srcfilesDirs, GenfilesDirs genfilesDirs, ImmutableList<Artifact> artifacts, File outputDir, File projectBuildOutputDirectory, File closureOutputDirectory, StableCssSubstitutionMapProvider substitutionMapProvider) { this.processRunner = processRunner; this.pluginDescriptor = pluginDescriptor; this.buildContext = buildContext; this.log = log; this.srcfilesDirs = srcfilesDirs; this.genfilesDirs = genfilesDirs; this.artifacts = artifacts; this.outputDir = outputDir; this.projectBuildOutputDirectory = projectBuildOutputDirectory; this.closureOutputDirectory = closureOutputDirectory; this.substitutionMapProvider = substitutionMapProvider; }
public SetupsMojoTestHelper( AbstractSetupsMojo mojo ) throws IOException { this.workingDir = new File( System.getProperty( "java.io.tmpdir" ), "unit_test_working" ); this.mojo = mojo; this.mojo.workingDir = this.workingDir.getCanonicalPath(); this.mojo.root = FitNesseHelper.DEFAULT_ROOT; this.mojo.project = new MavenProject(); this.mojo.project.setFile( new File( getClass().getResource( "pom.xml" ).getPath() ) ); this.mojo.pluginDescriptor = new PluginDescriptor(); this.mojo.pluginManager = mock( BuildPluginManager.class ); this.mojo.session = mock( MavenSession.class ); this.logStream = new ByteArrayOutputStream(); this.mojo.setLog( new DefaultLog( new PrintStreamLogger( Logger.LEVEL_INFO, "test", new PrintStream( this.logStream ) ) ) ); }
@SuppressWarnings( "unchecked" ) void setupArtifact( String groupId, String artifactId, String goal, String type ) throws DuplicateMojoDescriptorException, PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException { DefaultArtifact artifact = new DefaultArtifact( groupId, artifactId, "DUMMY", "compile", type, "", null ); MojoDescriptor mojoDescriptor = new MojoDescriptor(); mojoDescriptor.setGoal( goal ); PluginDescriptor pluginDescriptor = new PluginDescriptor(); pluginDescriptor.addMojo( mojoDescriptor ); Plugin plugin = new Plugin(); plugin.setGroupId( groupId ); plugin.setArtifactId( artifactId ); when( this.mojo.pluginManager.loadPlugin( eq( plugin ), anyList(), any( RepositorySystemSession.class ) ) ).thenReturn( pluginDescriptor ); this.mojo.pluginDescriptor.getArtifactMap().put( String.format( "%s:%s", groupId, artifactId ), artifact ); }
@Test public void extractionOfMojoSpecificConfigurationAndMergingwithDefaultMojoConfiguration() throws Exception { InputStream is = getClass().getResourceAsStream("/META-INF/maven/plugin.xml"); assertNotNull(is); PluginDescriptor pluginDescriptor = pluginDescriptorBuilder.build(new InputStreamReader(is, "UTF-8")); String goal = merger.determineGoal("io.takari.maven.plugins.jar.Jar", pluginDescriptor); assertEquals("We expect the goal name to be 'jar'", "jar", goal); MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo(goal); PlexusConfiguration defaultMojoConfiguration = mojoDescriptor.getMojoConfiguration(); System.out.println(defaultMojoConfiguration); PlexusConfiguration configurationFromMaven = builder("configuration") // .es("jar") // .es("sourceJar").v("true").ee() // .ee() // .buildPlexusConfiguration(); PlexusConfiguration mojoConfiguration = merger.extractAndMerge(goal, configurationFromMaven, defaultMojoConfiguration); String xml = mojoConfiguration.toString(); assertXpathEvaluatesTo("java.io.File", "/configuration/classesDirectory/@implementation", xml); assertXpathEvaluatesTo("${project.build.outputDirectory}", "/configuration/classesDirectory/@default-value", xml); assertXpathEvaluatesTo("java.util.List", "/configuration/reactorProjects/@implementation", xml); assertXpathEvaluatesTo("${reactorProjects}", "/configuration/reactorProjects/@default-value", xml); assertXpathEvaluatesTo("true", "/configuration/sourceJar", xml); }
/** * Taken from MojoExecutor of Don Brown. Make it working with Maven 3.1. * * @param plugin * @param goal * @param configuration * @param env * @throws MojoExecutionException * @throws PluginResolutionException * @throws PluginDescriptorParsingException * @throws InvalidPluginDescriptorException * @throws PluginManagerException * @throws PluginConfigurationException * @throws MojoFailureException */ private void executeMojo( Plugin plugin, String goal, Xpp3Dom configuration ) throws MojoExecutionException, PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException, MojoFailureException, PluginConfigurationException, PluginManagerException { if ( configuration == null ) { throw new NullPointerException( "configuration may not be null" ); } PluginDescriptor pluginDescriptor = getPluginDescriptor( plugin ); MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal ); if ( mojoDescriptor == null ) { throw new MojoExecutionException( "Could not find goal '" + goal + "' in plugin " + plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + plugin.getVersion() ); } MojoExecution exec = mojoExecution( mojoDescriptor, configuration ); pluginManager.executeMojo( getMavenSession(), exec ); }
public MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, List<RemoteRepository> repositories, RepositorySystemSession session ) throws MojoNotFoundException, PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException { PluginDescriptor pluginDescriptor = getPluginDescriptor( plugin, repositories, session ); MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal ); if ( mojoDescriptor == null ) { throw new MojoNotFoundException( goal, pluginDescriptor ); } return mojoDescriptor; }
public void checkRequiredMavenVersion( PluginDescriptor pluginDescriptor ) throws PluginIncompatibleException { String requiredMavenVersion = pluginDescriptor.getRequiredMavenVersion(); if ( StringUtils.isNotBlank( requiredMavenVersion ) ) { try { if ( !runtimeInformation.isMavenVersion( requiredMavenVersion ) ) { throw new PluginIncompatibleException( pluginDescriptor.getPlugin(), "The plugin " + pluginDescriptor.getId() + " requires Maven version " + requiredMavenVersion ); } } catch ( RuntimeException e ) { logger.warn( "Could not verify plugin's Maven prerequisite: " + e.getMessage() ); } } }
public PluginDescriptor getPluginDescriptorForPrefix( String prefix ) { MavenSession session = legacySupport.getSession(); PluginPrefixRequest request = new DefaultPluginPrefixRequest( prefix, session ); try { PluginPrefixResult result = pluginPrefixResolver.resolve( request ); Plugin plugin = new Plugin(); plugin.setGroupId( result.getGroupId() ); plugin.setArtifactId( result.getArtifactId() ); return loadPluginDescriptor( plugin, session.getCurrentProject(), session ); } catch ( Exception e ) { return null; } }
public PluginDescriptor loadPluginFully( Plugin plugin, MavenProject project, MavenSession session ) throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException, InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException, PluginVersionNotFoundException { PluginDescriptor pluginDescriptor = loadPluginDescriptor( plugin, project, session ); try { pluginManager.setupPluginRealm( pluginDescriptor, session, null, null, null ); } catch ( PluginResolutionException e ) { throw new PluginManagerException( plugin, e.getMessage(), e ); } return pluginDescriptor; }
public Map getPluginContext( PluginDescriptor plugin, MavenProject project ) { Map pluginContextsByKey = (Map) pluginContextsByProjectAndPluginKey.get( project.getId() ); if ( pluginContextsByKey == null ) { pluginContextsByKey = new HashMap(); pluginContextsByProjectAndPluginKey.put( project.getId(), pluginContextsByKey ); } Map pluginContext = (Map) pluginContextsByKey.get( plugin.getPluginLookupKey() ); if ( pluginContext == null ) { pluginContext = new HashMap(); pluginContextsByKey.put( plugin.getPluginLookupKey(), pluginContext ); } return pluginContext; }
public Map<String, Object> getPluginContext( PluginDescriptor plugin, MavenProject project ) { String projectKey = project.getId(); Map<String, Map<String, Object>> pluginContextsByKey = pluginContextsByProjectAndPluginKey.get( projectKey ); if ( pluginContextsByKey == null ) { pluginContextsByKey = new ConcurrentHashMap<String, Map<String, Object>>(); pluginContextsByProjectAndPluginKey.put( projectKey, pluginContextsByKey ); } String pluginKey = plugin.getPluginLookupKey(); Map<String, Object> pluginContext = pluginContextsByKey.get( pluginKey ); if ( pluginContext == null ) { pluginContext = new ConcurrentHashMap<String, Object>(); pluginContextsByKey.put( pluginKey, pluginContext ); } return pluginContext; }
Map<String, Object> retrieveContext( MavenSession session ) { Map<String, Object> context = null; if ( session != null ) { PluginDescriptor desc = new PluginDescriptor(); desc.setGroupId( PluginDescriptor.getDefaultPluginGroupId() ); desc.setArtifactId( PluginDescriptor.getDefaultPluginArtifactId( "toolchains" ) ); MavenProject current = session.getCurrentProject(); if ( current != null ) { //TODO: why is this using the context context = session.getPluginContext( desc, current ); } } return ( context != null ) ? context : new HashMap<String, Object>(); }
public void testMojoDescriptorRetrieval() throws Exception { MavenSession session = createMavenSession( null ); String goal = "it"; Plugin plugin = new Plugin(); plugin.setGroupId( "org.apache.maven.its.plugins" ); plugin.setArtifactId( "maven-it-plugin" ); plugin.setVersion( "0.1" ); MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, session.getCurrentProject().getRemotePluginRepositories(), session.getRepositorySession() ); assertNotNull( mojoDescriptor ); assertEquals( goal, mojoDescriptor.getGoal() ); // igorf: plugin realm comes later // assertNotNull( mojoDescriptor.getRealm() ); PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor(); assertNotNull( pluginDescriptor ); assertEquals( "org.apache.maven.its.plugins", pluginDescriptor.getGroupId() ); assertEquals( "maven-it-plugin", pluginDescriptor.getArtifactId() ); assertEquals( "0.1", pluginDescriptor.getVersion() ); }
private ExpressionEvaluator createExpressionEvaluator( MavenProject project, PluginDescriptor pluginDescriptor, Properties executionProperties ) throws Exception { ArtifactRepository repo = factory.createDefaultLocalRepository(); MutablePlexusContainer container = (MutablePlexusContainer) getContainer(); MavenSession session = createSession( container, repo, executionProperties ); session.setCurrentProject( project ); MojoDescriptor mojo = new MojoDescriptor(); mojo.setPluginDescriptor( pluginDescriptor ); mojo.setGoal( "goal" ); MojoExecution mojoExecution = new MojoExecution( mojo ); return new PluginParameterExpressionEvaluator( session, mojoExecution ); }
private void getMojosAndGoals(Model model, Plugin plugin) throws IOException, PlexusConfigurationException, Exception { String version = plugin.getVersion(); if (version != null && version.startsWith("$")) { version = model.getProperties().getProperty(plugin.getVersion().substring(2, plugin.getVersion().length() - 1)); plugin.setVersion(version); } Set<MojoDescriptor> mojoList = new HashSet<MojoDescriptor>(); try { PluginDescriptor pluginDesc = ProjectModelCache.getInstance().getPluginDescriptor(plugin); if (pluginDesc != null) { for (Object exec : pluginDesc.getMojos()) { MojoDescriptor mojoDesc = (MojoDescriptor) exec; mojoList.add(mojoDesc); } } } catch (Exception ex) { ex.printStackTrace(); } config.addMojos(plugin.getKey(), mojoList); }
public PluginDescriptor getPluginDescriptor(Plugin plugin) throws IOException, PlexusConfigurationException, Exception { synchronized (cache) { PluginDescriptor descriptor = (PluginDescriptor) cache.get(plugin.getKey()); if (descriptor == null) { String version = plugin.getVersion(); VersionRange range = null; if (version == null) { version = "LATEST"; range = VersionRange.createFromVersionSpec(version); } else { range = VersionRange.createFromVersion(version); } DefaultArtifact pluginArtifact = new DefaultArtifact(plugin.getGroupId(), plugin.getArtifactId(), range, null, "jar", null, new DefaultArtifactHandler("jar")); descriptor = MavenArtifactResolver.getInstance().getPluginDescriptor(pluginArtifact); cache.put(plugin.getKey(), descriptor); } return descriptor; } }
private static List<Artifact> resolveVersions(PluginDescriptor pluginDescriptor, String pluginArtifactId, List<ExpectedDependency> expectedDependencies) throws MojoExecutionException { List<Artifact> actualDependencies = new ArrayList<>(); for (Artifact artifact : pluginDescriptor.getArtifacts()) { if (! isExpected(artifact, expectedDependencies)) { continue; } if (isKnown(artifact, actualDependencies)) { continue; } failOnVersionConflict(artifact, actualDependencies, pluginArtifactId); actualDependencies.add(artifact); } return actualDependencies; }
public static void printWorkflow(String goalName, PluginDescriptor pluginDescriptor, Optional<File> customWorkflowDescriptor, Logger log) throws MojoExecutionException { StringBuilder sb = new StringBuilder(); if (StringUtils.isNotBlank(pluginDescriptor.getGoalPrefix())) { sb.append(pluginDescriptor.getGoalPrefix()); } else { sb.append(pluginDescriptor.getGroupId()).append(':').append(pluginDescriptor.getArtifactId()).append(':') .append(pluginDescriptor.getVersion()); } sb.append(':').append(goalName); log.info("Default workflow for '" + sb + "':"); InputStream workflowDescriptor = getWorkflowDescriptor(goalName, pluginDescriptor, customWorkflowDescriptor, log); try { int x = 77 - goalName.length(); int a = x / 2; int b = x % 2 == 1 ? a + 1 : a; StringBuilder separator = new StringBuilder(); separator.append(Strings.repeat("=", a)).append(' ').append(goalName).append(' ').append(Strings.repeat("=", b)); System.out.println(separator); ByteStreams.copy(workflowDescriptor, System.out); System.out.println(separator); } catch (IOException e) { throw new MojoExecutionException("A problem occurred during the serialization of the defualt workflow.", e); } finally { Closeables.closeQuietly(workflowDescriptor); } }
private void addPluginDependencies(Weld weld) throws MojoExecutionException { PluginDescriptor pluginDescriptor = getPluginDescriptor(); List<Dependency> dependencies = pluginDescriptor.getPlugin().getDependencies(); for (Dependency d : dependencies) { Optional<File> f = MavenUtil.resolvePluginDependency(d, this._pluginRepos, this._resolver, this._repoSystemSession); if (f.isPresent()) { CDIUtil.addAllClasses(weld, getClass().getClassLoader(), f.get(), getLog()); } else { throw new MojoExecutionException("Could not resolve the following plugin dependency: " + d); } } }
private String getGoalName() { PluginDescriptor pluginDescriptor = getPluginDescriptor(); for (MojoDescriptor mojoDescriptor : pluginDescriptor.getMojos()) { if (mojoDescriptor.getImplementation().equals(getClass().getName())) { return mojoDescriptor.getGoal(); } } return null; }
private MojoDescriptor getMavenBundleMojo() throws Exception { Plugin plugin = new Plugin(); plugin.setGroupId("org.apache.felix"); plugin.setArtifactId("maven-bundle-plugin"); plugin.setVersion("3.0.0"); plugin.setInherited(true); plugin.setExtensions(true); PluginDescriptor desc = pluginManager.loadPlugin(plugin, mavenProject.getRemotePluginRepositories(), mavenSession.getRepositorySession()); return desc.getMojo("bundle"); }
/** Adds steps to do extraction to the common planner. */ public void plan(Extracts unpreparedExtracts) throws MojoExecutionException { Extracts extracts = OptionsUtils.prepareOne(unpreparedExtracts); extracts = extracts.clone(); { PluginDescriptor pluginDescriptor = context.pluginDescriptor; Extract builtinExtract = new Extract(); builtinExtract.setArtifactId(pluginDescriptor.getArtifactId()); builtinExtract.setGroupId(pluginDescriptor.getGroupId()); builtinExtract.setVersion(pluginDescriptor.getVersion()); builtinExtract.setLoadAsNeeded(true); extracts.setExtract(builtinExtract); } ExtractRoot root = new ExtractRoot(context); root.setOptionSets(ImmutableList.of(extracts)); ImmutableSortedSet<FileExt> allExtensions = extensionsFor(extracts); joinNodes.pipeline() .then(root) .then(new ResolveExtracts(context)) .then(new ExtractFiles(context)) .provide(allExtensions) .build(); }
@SuppressWarnings("unchecked") protected void startProject(MavenProject project, String executionId, XmlPlexusConfiguration process) throws InvalidPluginDescriptorException, PluginResolutionException, PluginDescriptorParsingException, PluginNotFoundException, PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException { Plugin plugin = this.project.getPlugin("org.wildfly.swarm:wildfly-swarm-plugin"); Xpp3Dom config = getConfiguration(project, executionId); Xpp3Dom processConfig = getProcessConfiguration(process); Xpp3Dom globalConfig = getGlobalConfig(); Xpp3Dom mergedConfig = Xpp3DomUtils.mergeXpp3Dom(processConfig, config); mergedConfig = Xpp3DomUtils.mergeXpp3Dom(mergedConfig, globalConfig); PluginDescriptor pluginDescriptor = this.pluginManager.loadPlugin(plugin, project.getRemotePluginRepositories(), this.repositorySystemSession); MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo("start"); MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, mergedConfig); mavenSession.setCurrentProject(project); this.pluginManager.executeMojo(mavenSession, mojoExecution); List<SwarmProcess> launched = (List<SwarmProcess>) mavenSession.getPluginContext(pluginDescriptor, project).get(SWARM_PROCESS); List<SwarmProcess> procs = (List<SwarmProcess>) getPluginContext().get(SWARM_PROCESS); if (procs == null) { procs = new ArrayList<>(); getPluginContext().put(SWARM_PROCESS, procs); } procs.addAll(launched); mavenSession.setCurrentProject(this.project); }
@Before public void setUp() throws Exception { validator = new MavenPluginValidator( null ); desc = EasyMock.createMock( PluginDescriptor.class ); }
private static PluginDescriptor patchedClone(PluginDescriptor pluginDescriptor) { if (pluginDescriptor == null) return null; PluginDescriptor clone = clone(pluginDescriptor); clone.setDependencies(new ArrayList<ComponentDependency>(pluginDescriptor.getDependencies())); return clone; }
/** * Determine all plugin dependencies relevant to the executable. Takes * includePlugins, and the executableDependency into consideration. * * @return a set of Artifact objects. (Empty set is returned if there are no * relevant plugin dependencies.) * @throws MojoExecutionException */ private Set<Artifact> determineRelevantPluginDependencies() throws MojoExecutionException { Set<Artifact> relevantDependencies; if (this.includePluginDependencies) { if (this.executableDependency == null) { getLog().debug("All Plugin Dependencies will be included."); relevantDependencies = new HashSet<Artifact>(this.pluginDependencies); } else { getLog().debug("Selected plugin Dependencies will be included."); Artifact executableArtifact = this.findExecutableArtifact(); Artifact executablePomArtifact = this.getExecutablePomArtifact(executableArtifact); relevantDependencies = this.resolveExecutableDependencies(executablePomArtifact, false); } } else { getLog().debug("Only Direct Plugin Dependencies will be included."); PluginDescriptor descriptor = (PluginDescriptor) getPluginContext().get("pluginDescriptor"); try { relevantDependencies = artifactResolver .resolveTransitively(MavenMetadataSource .createArtifacts(this.artifactFactory, descriptor.getPlugin().getDependencies(), null, null, null), this.project.getArtifact(), Collections.emptyMap(), this.localRepository, this.remoteRepositories, metadataSource, new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME), Collections.emptyList()) .getArtifacts(); } catch (Exception ex) { throw new MojoExecutionException("Encountered problems resolving dependencies of the plugin " + "in preparation for its execution.", ex); } } return relevantDependencies; }
@SuppressWarnings("unchecked") protected void startProject(MavenProject project, String executionId, XmlPlexusConfiguration process) throws InvalidPluginDescriptorException, PluginResolutionException, PluginDescriptorParsingException, PluginNotFoundException, PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException { Plugin plugin = this.project.getPlugin("org.wildfly.swarm:wildfly-swarm-plugin"); Xpp3Dom config = getConfiguration(project, executionId); Xpp3Dom processConfig = getProcessConfiguration(process); Xpp3Dom globalConfig = getGlobalConfig(); Xpp3Dom mergedConfig = Xpp3DomUtils.mergeXpp3Dom(processConfig, config); mergedConfig = Xpp3DomUtils.mergeXpp3Dom(mergedConfig, globalConfig); PluginDescriptor pluginDescriptor = this.pluginManager.loadPlugin(plugin, project.getRemotePluginRepositories(), this.repositorySystemSession); MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo("start"); MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, mergedConfig); mavenSession.setCurrentProject(project); this.pluginManager.executeMojo(mavenSession, mojoExecution); List<SwarmProcess> launched = (List<SwarmProcess>) mavenSession.getPluginContext(pluginDescriptor, project).get("swarm-process"); List<SwarmProcess> procs = (List<SwarmProcess>) getPluginContext().get("swarm-process"); if (procs == null) { procs = new ArrayList<>(); getPluginContext().put("swarm-process", procs); } procs.addAll(launched); mavenSession.setCurrentProject(this.project); }
@Override public void execute() throws MojoExecutionException, MojoFailureException { this.pluginDescriptor = ((PluginDescriptor) getPluginContext().get("pluginDescriptor")); if (this.mavenHome == null ) { String mavenEnv = System.getenv("M2_HOME"); Validate.notEmpty(mavenEnv, "M2_HOME is not set you can used the maven-home configuration!"); mavenHome = new File(mavenEnv); } if (!mavenHome.exists() ) { throw new IllegalArgumentException("maven home (M2_HOME or maven-home configuration) is set to bad location : " + mavenHome.getAbsolutePath()); } OrFileFilter prefixFileFilter = new OrFileFilter(); prefixFileFilter.addFileFilter(new PrefixFileFilter("VDoc")); prefixFileFilter.addFileFilter(new PrefixFileFilter("VDP")); AndFileFilter fileFilter = new AndFileFilter(); fileFilter.addFileFilter(prefixFileFilter); fileFilter.addFileFilter(new SuffixFileFilter(".jar")); File[] earFiles = earFolder.listFiles((FileFilter) fileFilter); getLog().info("Scan the vdoc.ear folder"); deployFiles(earFiles); getLog().info("Scan the vdoc.ear/lib folder"); File[] earLibFiles = new File(earFolder, "lib").listFiles((FileFilter) fileFilter); deployFiles(earLibFiles); buildParentPom("sdk"); buildParentPom("sdk.advanced"); }
public PlexusConfiguration mojoConfigurationFor(Object mojoInstance, PlexusConfiguration pluginConfigurationFromMaven) throws ComponentConfigurationException { try (InputStream is = mojoInstance.getClass().getResourceAsStream("/META-INF/maven/plugin.xml")) { PluginDescriptor pd = pluginDescriptorBuilder.build(new InputStreamReader(is, "UTF-8")); // closes input stream too String goal = determineGoal(mojoInstance.getClass().getName(), pd); PlexusConfiguration defaultMojoConfiguration = pd.getMojo(goal).getMojoConfiguration(); PlexusConfiguration mojoConfiguration = extractAndMerge(goal, pluginConfigurationFromMaven, defaultMojoConfiguration); return mojoConfiguration; } catch (Exception e) { throw new ComponentConfigurationException(e); } }
String determineGoal(String className, PluginDescriptor pluginDescriptor) throws ComponentConfigurationException { List<MojoDescriptor> mojos = pluginDescriptor.getMojos(); for (MojoDescriptor mojo : mojos) { if (className.equals(mojo.getImplementation())) { return mojo.getGoal(); } } throw new ComponentConfigurationException("Cannot find the goal implementation with " + className); }
/** * @return the goal prefix parameter or the goal prefix from the Plugin artifactId. */ private String getGoalPrefix() { if (goalPrefix == null) { goalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId(project.getArtifactId()); } return goalPrefix; }
@Test public void determineGoalFromMojoImplementation() throws Exception { InputStream is = getClass().getResourceAsStream("/META-INF/maven/plugin.xml"); assertNotNull(is); PluginDescriptor pluginDescriptor = pluginDescriptorBuilder.build(new InputStreamReader(is, "UTF-8")); String goal = merger.determineGoal("io.takari.maven.plugins.jar.Jar", pluginDescriptor); assertEquals("We expect the goal name to be 'jar'", "jar", goal); }
private MojoExecution newMojoExecution(Xpp3Dom... parameters) throws IOException { MojoExecution execution = mojos.newMojoExecution("testProperties", parameters); PluginDescriptor pluginDescriptor = execution.getMojoDescriptor().getPluginDescriptor(); ArtifactHandler handler = new DefaultArtifactHandler("jar"); DefaultArtifact workspaceResolver = new DefaultArtifact("io.takari.m2e.workspace", "org.eclipse.m2e.workspace.cli", "1", Artifact.SCOPE_COMPILE, ".jar", null, handler); workspaceResolver.setFile(new File("target/workspaceResolver.jar").getCanonicalFile()); List<Artifact> pluginArtifacts = new ArrayList<>(pluginDescriptor.getArtifacts()); pluginArtifacts.add(workspaceResolver); pluginDescriptor.setArtifacts(pluginArtifacts); return execution; }