private void validateProjects( List<MavenProject> projects ) { Map<String, MavenProject> projectsMap = new HashMap<>(); for ( MavenProject p : projects ) { String projectKey = ArtifactUtils.key( p.getGroupId(), p.getArtifactId(), p.getVersion() ); projectsMap.put( projectKey, p ); } for ( MavenProject project : projects ) { // MNG-1911 / MNG-5572: Building plugins with extensions cannot be part of reactor for ( Plugin plugin : project.getBuildPlugins() ) { if ( plugin.isExtensions() ) { String pluginKey = ArtifactUtils.key( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() ); if ( projectsMap.containsKey( pluginKey ) ) { logger.warn( project.getName() + " uses " + plugin.getKey() + " as extensions, which is not possible within the same reactor build. " + "This plugin was pulled from the local repository!" ); } } } } }
public static Plugin clonePlugin( Plugin src ) { Plugin result = null; if ( src != null ) { result = new Plugin(); result.setArtifactId( src.getArtifactId() ); result.setConfiguration( cloneConfiguration( src.getConfiguration() ) ); result.setDependencies( cloneList( src.getDependencies(), DEPENDENCY_CLONER ) ); result.setExecutions( cloneList( src.getExecutions(), PLUGIN_EXECUTION_CLONER ) ); result.setExtensions( src.isExtensions() ); result.setGroupId( src.getGroupId() ); result.setInherited( src.getInherited() ); result.setVersion( src.getVersion() ); } return result; }
public PluginManagerException( Plugin plugin, String message, MavenProject project ) { super( message ); pluginGroupId = plugin.getGroupId(); pluginArtifactId = plugin.getArtifactId(); pluginVersion = plugin.getVersion(); this.project = project; }
protected void mergePlugin_Version( Plugin target, Plugin source, boolean sourceDominant, Map<Object, Object> context ) { String src = source.getVersion(); if ( src != null ) { if ( sourceDominant || target.getVersion() == null ) { target.setVersion( src ); target.setLocation( "version", source.getLocation( "version" ) ); } } }
protected void mergePlugin_GroupId( Plugin target, Plugin source, boolean sourceDominant, Map<Object, Object> context ) { String src = source.getGroupId(); if ( src != null ) { if ( sourceDominant || target.getGroupId() == null ) { target.setGroupId( src ); target.setLocation( "groupId", source.getLocation( "groupId" ) ); } } }
project.setModel( model ); project.setOriginalModel( result.getRawModel() ); project.setFile( model.getPomFile() ); Build build = project.getBuild(); project.addScriptSourceRoot( build.getScriptSourceDirectory() ); project.addCompileSourceRoot( build.getSourceDirectory() ); project.addTestCompileSourceRoot( build.getTestSourceDirectory() ); for ( ReportPlugin report : project.getReportPlugins() ) Plugin pp = new Plugin(); pp.setGroupId( report.getGroupId() ); pp.setArtifactId( report.getArtifactId() ); pp.setVersion( report.getVersion() );
throw new DuplicateProjectException( projectId, conflictingProject.getFile(), project.getFile(), "Project '" + projectId + "' is duplicated in the reactor" ); String projectKey = ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ); Parent parent = project.getModel().getParent(); addEdge( projectMap, vertexMap, project, projectVertex, plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion(), false, true ); for ( Dependency dependency : plugin.getDependencies() )
@Override public void validateEffectiveModel( Model m, ModelBuildingRequest request, ModelProblemCollector problems ) validateStringNotEmpty( "modelVersion", problems, Severity.ERROR, Version.BASE, m.getModelVersion(), m ); validateId( "groupId", problems, m.getGroupId(), m ); validateId( "artifactId", problems, m.getArtifactId(), m ); validateStringNotEmpty( "packaging", problems, Severity.ERROR, Version.BASE, m.getPackaging(), m ); if ( build != null ) for ( Plugin p : build.getPlugins() ) p.getArtifactId(), p ); p.getGroupId(), p ); validate20PluginVersion( "build.plugins.plugin.version", problems, p.getVersion(), p.getKey(), p, request ); validateBoolean( "build.plugins.plugin.inherited", problems, errOn30, Version.V20, p.getInherited(), p.getKey(), p ); p.getExtensions(), p.getKey(), p ); validate20RawResources( problems, build.getResources(), "build.resources.resource", request );
validateStringNotEmpty( "modelVersion", result, model.getModelVersion() ); validateId( "groupId", result, model.getGroupId() ); validateId( "artifactId", result, model.getArtifactId() ); validateStringNotEmpty( "packaging", result, model.getPackaging() ); if ( build != null ) for ( Iterator it = build.getPlugins().iterator(); it.hasNext(); ) validateStringNotEmpty( "build.plugins.plugin.artifactId", result, p.getArtifactId() ); validateStringNotEmpty( "build.plugins.plugin.groupId", result, p.getGroupId() ); for ( Iterator it = build.getResources().iterator(); it.hasNext(); ) for ( Iterator it = build.getTestResources().iterator(); it.hasNext(); )
@Override public void afterProjectsRead(MavenSession session) throws MavenExecutionException { try { Map<String, MavenProject> projectMap = new HashMap<String, MavenProject>(); for (MavenProject project : session.getProjects()) { projectMap.put(project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion(), project); } for (MavenProject project : session.getProjects()) { for (Plugin plugin : project.getBuild().getPlugins()) { if (plugin.getArtifactId().equals(PLUGIN_ID)) { BundleListDependencyAdder performer = new BundleListDependencyAdder(session, project, plugin); performer.addDependencies(); } } } } catch (Exception e) { throw new MavenExecutionException("Unable to determine launchpad plugin-based dependencies", e); } super.afterProjectsRead(session); }
Build build = model.getBuild(); if (build == null) { build = new Build(); model.setBuild(build); List<Plugin> plugins = build.getPlugins(); if (plugins == null) { plugins = new ArrayList<>(); build.setPlugins(plugins); Optional<Plugin> pluginOptional = plugins.stream().filter(plugin -> plugin.getGroupId().equals(MULE_MAVEN_PLUGIN_GROUP_ID) && plugin.getArtifactId().equals(MULE_MAVEN_PLUGIN_ARTIFACT_ID)).findFirst(); List<Plugin> finalPlugins = plugins; Plugin plugin = pluginOptional.orElseGet(() -> { Plugin muleMavenPlugin = new Plugin(); muleMavenPlugin.setGroupId(MULE_MAVEN_PLUGIN_GROUP_ID); muleMavenPlugin.setArtifactId(MULE_MAVEN_PLUGIN_ARTIFACT_ID); finalPlugins.add(muleMavenPlugin); return muleMavenPlugin; }); Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration(); if (configuration == null) { configuration = new Xpp3Dom("configuration"); plugin.setConfiguration(configuration);
@Override public void convertReporting( Model model, ModelBuildingRequest request, ModelProblemCollector problems ) Reporting reporting = model.getReporting(); Build build = model.getBuild(); sitePlugin = new Plugin(); sitePlugin.setArtifactId( "maven-site-plugin" ); PluginManagement pluginManagement = build.getPluginManagement(); if ( pluginManagement == null ) pluginManagement.addPlugin( sitePlugin ); Xpp3Dom configuration = (Xpp3Dom) sitePlugin.getConfiguration(); configuration = new Xpp3Dom( "configuration" ); sitePlugin.setConfiguration( configuration ); Xpp3Dom reportPlugins = configuration.getChild( "reportPlugins" ); .setMessage( "Reporting configuration should be done in <reporting> section, " + "not in maven-site-plugin <configuration> as reportPlugins parameter." ) .setLocation( sitePlugin.getLocation( "configuration" ) ) ); return; if ( configuration.getChild( "outputDirectory" ) == null )
Set<ArtifactKey> artifacts = new HashSet<ArtifactKey>(); Map<ArtifactKey, String> managed = new HashMap<ArtifactKey, String>(); if(mp != null && mp.getBuild() != null) { PluginManagement pm = mp.getBuild().getPluginManagement(); if(pm != null && pm.getPlugins() != null) { for(Plugin plug : pm.getPlugins()) { ArtifactKey artifactKey = new ArtifactKey(plug.getGroupId(), plug.getArtifactId(), plug.getVersion(), null); if(inManagedSection) { artifacts.add(artifactKey); if(!inManagedSection && mp.getModel().getBuild() != null) { for(Plugin plug : mp.getModel().getBuild().getPlugins()) { artifacts.add(new ArtifactKey(plug.getGroupId(), plug.getArtifactId(), plug.getVersion(), null));
public static String getPluginConfigParameter ( MavenProject project, String parameter, String defaultValue ) { String value = null; for ( Plugin plugin : project.getBuild().getPlugins() ) { if ( plugin.getArtifactId().equals( PluginInfo.getArtifactId() ) ) { Xpp3Dom configuration = getMojoConfiguration( plugin ); if ( configuration != null && configuration.getChild( parameter ) != null ) { value = configuration.getChild( parameter ).getValue() ; } } } // if we got nothing, fall back to the default value return ( StringUtils.isEmpty( value ) ) ? defaultValue : value; }
private List<String> getSources(final MavenProject module, final String target) { Map<String, Plugin> plugins = project.getPluginManagement() .getPluginsAsMap(); Plugin scalacPlugin = plugins.get(SCALA_MAVEN_PLUGIN); List<String> sources = Optional.ofNullable(scalacPlugin).map(p -> p.getConfiguration()) .flatMap(obj -> { if(obj instanceof Xpp3Dom) { Xpp3Dom config = (Xpp3Dom) obj; return Optional.ofNullable(config.getChild("sources")) .map(c -> Arrays.stream(c.getChildren()) .map(v -> v.getValue()).collect(toList())); } else return Optional.empty(); }).orElse(new ArrayList()); if(sources.isEmpty()) { sources = Stream.of( new File(module.getBasedir().getAbsolutePath() + SP + "src" + SP + target + SP + "scala"), new File(module.getBasedir().getAbsolutePath() + SP + "src" + SP + target + SP + "java")).map(f -> f.getAbsolutePath()).collect(toList()); } sources.addAll(module.getCompileSourceRoots()); return sources; }
private void mergeDeterministicPluginElements( List iPlugins, List dPlugins ) { if ( dPlugins != null ) { for ( int i = 0; i < dPlugins.size(); i++ ) { Plugin dPlugin = (Plugin) dPlugins.get( i ); Plugin iPlugin = (Plugin) iPlugins.get( i ); dPlugin.setGroupId( iPlugin.getGroupId() ); dPlugin.setArtifactId( iPlugin.getArtifactId() ); dPlugin.setVersion( iPlugin.getVersion() ); dPlugin.setDependencies( iPlugin.getDependencies() ); List dExecutions = dPlugin.getExecutions(); if ( dExecutions != null ) { List iExecutions = iPlugin.getExecutions(); for ( int j = 0; j < dExecutions.size(); j++ ) { PluginExecution dExec = (PluginExecution) dExecutions.get( j ); PluginExecution iExec = (PluginExecution) iExecutions.get( j ); dExec.setId( iExec.getId() ); } } } } }
if ( parent.isExtensions() ) child.setExtensions( true ); if ( ( child.getVersion() == null ) && ( parent.getVersion() != null ) ) child.setVersion( parent.getVersion() ); Xpp3Dom childConfiguration = (Xpp3Dom) child.getConfiguration(); Xpp3Dom parentConfiguration = (Xpp3Dom) parent.getConfiguration(); childConfiguration = Xpp3Dom.mergeXpp3Dom( childConfiguration, parentConfiguration ); child.setConfiguration( childConfiguration ); child.setDependencies( mergeDependencyList( child.getDependencies(), parent.getDependencies() ) ); String parentInherited = parent.getInherited(); List<PluginExecution> parentExecutions = parent.getExecutions(); Map<String, PluginExecution> childExecutions = child.getExecutionsAsMap(); for ( PluginExecution childExecution : child.getExecutions() ) child.setExecutions( mergedExecutions ); child.flushExecutionMap();
if ( getBuildPlugins() != null ) for ( Plugin plugin : getBuildPlugins() ) if ( pluginGroupId.equals( plugin.getGroupId() ) && pluginArtifactId.equals( plugin.getArtifactId() ) ) dom = (Xpp3Dom) plugin.getConfiguration(); PluginExecution execution = plugin.getExecutionsAsMap().get( executionId ); if ( execution != null ) dom = (Xpp3Dom) execution.getConfiguration(); dom = new Xpp3Dom( dom );
Plugin plugin = new Plugin(); plugin.setGroupId( gs.groupId ); plugin.setArtifactId( gs.artifactId ); plugin.setVersion( gs.version ); if ( existing.getVersion() == null ) existing.setVersion( plugin.getVersion() ); PluginExecution execution = new PluginExecution(); execution.setId( getExecutionId( plugin, gs.goal ) ); execution.setPhase( phase ); execution.setPriority( i - mojos.size() ); execution.getGoals().add( gs.goal ); if ( lifecycleConfiguration != null ) execution.setConfiguration( new Xpp3Dom( lifecycleConfiguration ) ); plugin.setDependencies( mojo.getDependencies() ); plugin.getExecutions().add( execution );
protected void doExecute() throws MojoExecutionException { getUpdateChecker().check(); trackFirstRunIfNeeded(); getGoogleTracker().track(GoogleAmpsTracker.RUN_STANDALONE); try { MavenGoals goals; Xpp3Dom configuration; goals = createMavenGoals(projectBuilder); /* When we run with Maven 3 the configuration from the pom isn't automatically picked up * by the mojo executor. Grab it manually from pluginManagement. */ PluginManagement mgmt = goals.getContextProject().getBuild().getPluginManagement(); Plugin plugin = mgmt.getPluginsAsMap().get("com.atlassian.maven.plugins:amps-maven-plugin"); configuration = (Xpp3Dom) plugin.getConfiguration(); goals.executeAmpsRecursively(getPluginInformation().getVersion(), getAmpsGoal(), configuration); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } }