protected void addBuild() { Build build = model.getBuild(); if (build == null) { build = new Build(); } if (bwEdition.equals("cf")) { boolean cfplugin = false; List<Plugin> plugins = build.getPlugins(); for (Plugin plg : plugins) { if (plg.getArtifactId().equals("cf-maven-plugin")) { cfplugin = true; } } // Add only if doesn't exist if (!cfplugin) { addPCFWithSkipMavenPlugin(build); } } else if (bwEdition.equals("docker")) { boolean dockerPlugin = false; List<Plugin> plugins = build.getPlugins(); for (Plugin plg : plugins) { if (plg.getArtifactId().equals("docker-maven-plugin")) { dockerPlugin = true; } } if (!dockerPlugin) { // Add docker and platform plugins if doesn't exist addDockerWithSkipMavenPlugin(build); String platform = ""; for (BWModule module : project.getModules()) { if (module.getType() == BWModuleType.Application) { platform = module.getBwDockerModule().getPlatform(); } } if (platform.equals("K8S")) { addDockerK8SMavenPlugin(build, true); } else if (platform.equals("Mesos")) { } else if (platform.equals("Swarm")) { } } } model.setBuild(build); }
private List<String> getPackages( List<String> exportedPackagesList, MavenProject mavenProject, String packagetype) throws CoreException, JavaModelException, Exception { List<Plugin> plugins = mavenProject.getBuild().getPlugins(); for (Plugin plugin : plugins) { if ("maven-bundle-plugin".equalsIgnoreCase(plugin.getArtifactId())) { Xpp3Dom configurationNode = (Xpp3Dom) plugin.getConfiguration(); Xpp3Dom[] instructions = configurationNode.getChildren("instructions"); if (instructions.length == 1) { Xpp3Dom[] exportPackage = instructions[0].getChildren(packagetype); if (exportPackage.length == 1) { exportedPackagesList.clear(); // clear default configuration (All packages by default) String exportpackages = exportPackage[0].getValue(); if (exportpackages != null) { exportedPackagesList.addAll(Arrays.asList(exportpackages.split(","))); } } else { log.warn( "Invalid configuration for <Export-Package> entry" + " using default configuration for <Export-Package>"); } } else { log.warn( "Invalid instructions configuration for plugin : maven-bundle-plugin" + " using default configuration for <Export-Package>"); } break; // not considering multiple versions of the maven-bundle-plugin } } return exportedPackagesList; }
private List<MavenProject> fabricZipGoalProjects() { List<MavenProject> answer = new ArrayList<>(); if (reactorProjects != null) { List<MavenProject> pomZipProjects = new ArrayList<>(); for (MavenProject reactorProject : reactorProjects) { if (isPom(reactorProject)) { pomZipProjects.add(reactorProject); } List<Plugin> buildPlugins = reactorProject.getBuildPlugins(); for (Plugin buildPlugin : buildPlugins) { String artifactId = buildPlugin.getArtifactId(); if ("fabric8-maven-plugin".equals(artifactId)) { Object goals = buildPlugin.getGoals(); boolean hasZipGoal = goals != null && goals.toString().contains("zip"); List<PluginExecution> executions = buildPlugin.getExecutions(); for (PluginExecution execution : executions) { List<String> execGoals = execution.getGoals(); if (execGoals.contains("zip")) { hasZipGoal = true; } } getLog() .debug( "Project " + reactorProject.getArtifactId() + " has zip goal: " + hasZipGoal); if (hasZipGoal) { answer.add(reactorProject); } } } } } return answer; }
@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); }
private static String getKey(Plugin plugin, boolean extension) { String version = ArtifactUtils.toSnapshotVersion(plugin.getVersion()); return (extension ? "extension>" : "plugin>") + plugin.getGroupId() + ":" + plugin.getArtifactId() + ":" + version; }
private List<String> alterModel(MavenProject project, String newVersion) { Model originalModel = project.getOriginalModel(); originalModel.setVersion(newVersion); List<String> errors = new ArrayList<String>(); String searchingFrom = project.getArtifactId(); MavenProject parent = project.getParent(); if (parent != null && isSnapshot(parent.getVersion())) { try { ReleasableModule parentBeingReleased = reactor.find(parent.getGroupId(), parent.getArtifactId(), parent.getVersion()); originalModel.getParent().setVersion(parentBeingReleased.getVersionToDependOn()); log.debug( " Parent " + parentBeingReleased.getArtifactId() + " rewritten to version " + parentBeingReleased.getVersionToDependOn()); } catch (UnresolvedSnapshotDependencyException e) { errors.add("The parent of " + searchingFrom + " is " + e.artifactId + " " + e.version); } } for (Dependency dependency : originalModel.getDependencies()) { String version = dependency.getVersion(); if (isSnapshot(version)) { try { ReleasableModule dependencyBeingReleased = reactor.find(dependency.getGroupId(), dependency.getArtifactId(), version); dependency.setVersion(dependencyBeingReleased.getVersionToDependOn()); log.debug( " Dependency on " + dependencyBeingReleased.getArtifactId() + " rewritten to version " + dependencyBeingReleased.getVersionToDependOn()); } catch (UnresolvedSnapshotDependencyException e) { errors.add(searchingFrom + " references dependency " + e.artifactId + " " + e.version); } } else log.debug( " Dependency on " + dependency.getArtifactId() + " kept at version " + dependency.getVersion()); } for (Plugin plugin : project.getModel().getBuild().getPlugins()) { String version = plugin.getVersion(); if (isSnapshot(version)) { if (!isMultiModuleReleasePlugin(plugin)) { errors.add( searchingFrom + " references plugin " + plugin.getArtifactId() + " " + version); } } } return errors; }
/** * Set the versions of any plugins which match the contents of the list of plugin overrides * * @param plugins The list of plugins to modify * @param pluginVersionOverrides The list of version overrides to apply to the plugins */ private static void applyOverrides( List<Plugin> plugins, Map<String, String> pluginVersionOverrides) { for (Plugin plugin : plugins) { String groupIdArtifactId = plugin.getGroupId() + GAV_SEPERATOR + plugin.getArtifactId(); if (pluginVersionOverrides.containsKey(groupIdArtifactId)) { String overrideVersion = pluginVersionOverrides.get(groupIdArtifactId); plugin.setVersion(overrideVersion); Log.getLog().debug("Altered plugin: " + groupIdArtifactId + "=" + overrideVersion); } } }
@Override public void generate(final File reportsDir, final VersionManagerSession session) throws VManException { Map<VersionlessProjectKey, Set<Plugin>> missingPlugins = session.getUnmanagedPluginRefs(); if (missingPlugins.isEmpty()) { return; } Element plugins = new Element("plugins"); for (Map.Entry<VersionlessProjectKey, Set<Plugin>> pluginsEntry : missingPlugins.entrySet()) { if (plugins.getContentSize() > 0) { plugins.addContent("\n\n"); } plugins.addContent(new Comment("START: " + pluginsEntry.getKey())); for (Plugin dep : pluginsEntry.getValue()) { Element d = new Element("plugin"); plugins.addContent(d); d.addContent(new Element("groupId").setText(dep.getGroupId())); d.addContent(new Element("artifactId").setText(dep.getArtifactId())); d.addContent(new Element("version").setText(dep.getVersion())); } plugins.addContent(new Comment("END: " + pluginsEntry.getKey())); } Element build = new Element("build"); build.addContent(new Element("pluginManagement").setContent(plugins)); Document doc = new Document(build); Format fmt = Format.getPrettyFormat(); fmt.setIndent(" "); fmt.setTextMode(TextMode.PRESERVE); XMLOutputter output = new XMLOutputter(fmt); File report = new File(reportsDir, ID + ".xml"); FileWriter writer = null; try { reportsDir.mkdirs(); writer = new FileWriter(report); output.output(doc, writer); } catch (IOException e) { throw new VManException("Failed to generate %s report! Error: %s", e, ID, e.getMessage()); } finally { closeQuietly(writer); } }
@Override public void removePlugin(Dependency dependency) { MavenCoreFacet mavenCoreFacet = project.getFacet(MavenCoreFacet.class); List<Plugin> pomPlugins = mavenCoreFacet.getPOM().getBuild().getPlugins(); for (Plugin pomPlugin : pomPlugins) { if (pomPlugin.getGroupId().equals(dependency.getGroupId()) && pomPlugin.getArtifactId().equals(dependency.getArtifactId())) { Model pom = mavenCoreFacet.getPOM(); pom.getBuild().removePlugin(pomPlugin); mavenCoreFacet.setPOM(pom); } } }
// DefaultProjectBuilder public Artifact createPluginArtifact(Plugin plugin) { VersionRange versionRange; try { String version = plugin.getVersion(); if (StringUtils.isEmpty(version)) { version = "RELEASE"; } versionRange = VersionRange.createFromVersionSpec(version); } catch (InvalidVersionSpecificationException e) { return null; } return XcreatePluginArtifact(plugin.getGroupId(), plugin.getArtifactId(), versionRange); }
@Override public boolean install() { if (!this.isInstalled()) { for (DirectoryResource folder : this.getSourceFolders()) { folder.mkdirs(); } // FIXME WOW this needs to be simplified somehow... MavenCoreFacet maven = project.getFacet(MavenCoreFacet.class); Model pom = maven.getPOM(); Build build = pom.getBuild(); if (build == null) { build = new Build(); } List<Plugin> plugins = build.getPlugins(); Plugin javaSourcePlugin = null; for (Plugin plugin : plugins) { if ("org.apache.maven.plugins".equals(plugin.getGroupId()) && "maven-compiler-plugin".equals(plugin.getArtifactId())) { javaSourcePlugin = plugin; } } if (javaSourcePlugin == null) { javaSourcePlugin = new Plugin(); // FIXME this should find the most recent version using DependencyResolver javaSourcePlugin.setGroupId("org.apache.maven.plugins"); javaSourcePlugin.setArtifactId("maven-compiler-plugin"); javaSourcePlugin.setVersion("2.3.2"); try { Xpp3Dom dom = Xpp3DomBuilder.build( new ByteArrayInputStream( "<configuration><source>1.6</source><target>1.6</target></configuration>" .getBytes()), "UTF-8"); javaSourcePlugin.setConfiguration(dom); } catch (Exception e) { throw new ProjectModelException(e); } } build.addPlugin(javaSourcePlugin); pom.setBuild(build); maven.setPOM(pom); } return true; }
@Test public void testSetupCommand() throws Exception { Project project = initializeJavaProject(); getShell().execute("jacoco setup"); MavenCoreFacet facet = project.getFacet(MavenCoreFacet.class); Model pom = facet.getPOM(); Profile jacocoProfile = pom.getProfiles().get(0); assertEquals("jacoco", jacocoProfile.getId()); Plugin jacocoPlugin = jacocoProfile.getBuild().getPlugins().get(0); assertEquals("jacoco-maven-plugin", jacocoPlugin.getArtifactId()); PluginExecution exec = jacocoPlugin.getExecutions().get(0); assertEquals("prepare-agent", exec.getGoals().get(0)); }
public List<IResource> exportArtifact(IProject project) throws Exception { String projectPath = project.getLocation().toFile().toString(); List<IResource> exportResources = new ArrayList<IResource>(); clearTarget(project); IFile pomFile = project.getFile("pom.xml"); if (pomFile.exists()) { MavenProject mavenProject = MavenUtils.getMavenProject(pomFile.getLocation().toFile()); List<Plugin> plugins = mavenProject.getBuild().getPlugins(); for (Plugin plugin : plugins) { if (plugin.getArtifactId().equals("maven-dataservice-plugin") && plugin.getGroupId().equals("org.wso2.maven")) { Xpp3Dom artifactNode = ((Xpp3Dom) plugin.getConfiguration()).getChild("artifact"); String dbsFile = artifactNode.getValue(); String[] pathArray = dbsFile.split("/"); IFile dbsFileRef = project .getFolder("src") .getFolder("main") .getFolder("dataservice") .getFile(pathArray[pathArray.length - 1]); if (dbsFileRef.exists()) { exportResources.add((IResource) dbsFileRef); } } } } else { File[] dbsFiles = FileUtils.getAllMatchingFiles( project.getLocation().toString(), null, DBS_FILE_EXTENSION, new ArrayList<File>()); for (File dbsFile : dbsFiles) { String filePath = dbsFile.toString(); // excluded any files inside target dir if (!filePath .substring(projectPath.length()) .startsWith(File.separator + "target" + File.separator)) { IFile dbsFileRef = ResourcesPlugin.getWorkspace() .getRoot() .getFileForLocation(Path.fromOSString(dbsFile.getAbsolutePath())); exportResources.add((IResource) dbsFileRef); } } } return exportResources; }
@Override public List<MavenPlugin> listConfiguredPlugins() { MavenCoreFacet mavenCoreFacet = project.getFacet(MavenCoreFacet.class); List<Plugin> pomPlugins = mavenCoreFacet.getPOM().getBuild().getPlugins(); List<MavenPlugin> plugins = new ArrayList<MavenPlugin>(); for (Plugin plugin : pomPlugins) { MavenPluginAdapter adapter = new MavenPluginAdapter(plugin); MavenPluginBuilder pluginBuilder = MavenPluginBuilder.create() .setDependency( DependencyBuilder.create() .setGroupId(plugin.getGroupId()) .setArtifactId(plugin.getArtifactId()) .setVersion(plugin.getVersion())) .setConfiguration(adapter.getConfig()); plugins.add(pluginBuilder); } return plugins; }
/* (non-Javadoc) * @see org.apache.maven.plugin.Mojo#execute() */ public void execute() throws MojoExecutionException, MojoFailureException { if (project.getFile() != null) { boolean found = false; Plugin plugin = null; // Search for this plugin in project pom for (Iterator iter = plugins.iterator(); iter.hasNext(); ) { plugin = (Plugin) iter.next(); if ("maven-cdk-plugin".equals(plugin.getArtifactId())) { String groupId; if ("3.1.0".compareTo(plugin.getVersion()) > 0) { groupId = "org.ajax4jsf.cdk"; } else { groupId = "org.richfaces.cdk"; } if (groupId.equals(plugin.getGroupId())) { found = true; break; } } } if (found) { try { createComponent(plugin); } catch (Exception e) { throw new MojoExecutionException("Error on create component", e); } } else { throw new MojoFailureException( "This project is not configured for JSF components generation"); } } else { throw new MojoFailureException("Goal 'create' must be run in existing project directory"); } }
@Override public void resolveProjectDependencies( final IMavenProjectFacade facade, Set<Capability> capabilities, Set<RequiredCapability> requirements, final IProgressMonitor monitor) throws CoreException { long start = System.currentTimeMillis(); log.debug("Resolving dependencies for {}", facade.toString()); // $NON-NLS-1$ markerManager.deleteMarkers(facade.getPom(), IMavenConstants.MARKER_DEPENDENCY_ID); ProjectBuildingRequest configuration = getMaven().getExecutionContext().newProjectBuildingRequest(); configuration.setProject(facade.getMavenProject()); // TODO do we need this? configuration.setResolveDependencies(true); MavenExecutionResult mavenResult = getMaven().readMavenProject(facade.getPomFile(), configuration); markerManager.addMarkers(facade.getPom(), IMavenConstants.MARKER_DEPENDENCY_ID, mavenResult); if (!facade.getResolverConfiguration().shouldResolveWorkspaceProjects()) { return; } MavenProject mavenProject = facade.getMavenProject(); // dependencies // resolved dependencies for (Artifact artifact : mavenProject.getArtifacts()) { requirements.add( MavenRequiredCapability.createMavenArtifact( new ArtifactKey(artifact), artifact.getScope(), artifact.isOptional())); } // extension plugins (affect packaging type calculation) for (Plugin plugin : mavenProject.getBuildPlugins()) { if (plugin.isExtensions()) { ArtifactKey artifactKey = new ArtifactKey(plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion(), null); requirements.add( MavenRequiredCapability.createMavenArtifact( artifactKey, "plugin", false)); // $NON-NLS-1$ } } // missing dependencies DependencyResolutionResult resolutionResult = mavenResult.getDependencyResolutionResult(); if (resolutionResult != null && resolutionResult.getUnresolvedDependencies() != null) { for (Dependency dependency : resolutionResult.getUnresolvedDependencies()) { org.eclipse.aether.artifact.Artifact artifact = dependency.getArtifact(); ArtifactKey dependencyKey = new ArtifactKey( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), null); requirements.add( MavenRequiredCapability.createMavenArtifact( dependencyKey, dependency.getScope(), dependency.isOptional())); } } log.debug( "Resolved dependencies for {} in {} ms", facade.toString(), System.currentTimeMillis() - start); // $NON-NLS-1$ }
public void testProjectInheritance() throws Exception { File localRepo = getLocalRepositoryPath(); System.out.println("Local repository is at: " + localRepo.getAbsolutePath()); File pom0 = new File(localRepo, "p0/pom.xml"); File pom1 = new File(pom0.getParentFile(), "p1/pom.xml"); File pom2 = new File(pom1.getParentFile(), "p2/pom.xml"); File pom3 = new File(pom2.getParentFile(), "p3/pom.xml"); File pom4 = new File(pom3.getParentFile(), "p4/pom.xml"); File pom5 = new File(pom4.getParentFile(), "p5/pom.xml"); System.out.println("Location of project-4's POM: " + pom4.getPath()); // load everything... MavenProject project0 = getProject(pom0); MavenProject project1 = getProject(pom1); MavenProject project2 = getProject(pom2); MavenProject project3 = getProject(pom3); MavenProject project4 = getProject(pom4); MavenProject project5 = getProject(pom5); assertEquals("p4", project4.getName()); // ---------------------------------------------------------------------- // Value inherited from p3 // ---------------------------------------------------------------------- assertEquals("2000", project4.getInceptionYear()); // ---------------------------------------------------------------------- // Value taken from p2 // ---------------------------------------------------------------------- assertEquals("mailing-list", project4.getMailingLists().get(0).getName()); // ---------------------------------------------------------------------- // Value taken from p1 // ---------------------------------------------------------------------- assertEquals("scm-url/p2/p3/p4", project4.getScm().getUrl()); // ---------------------------------------------------------------------- // Value taken from p4 // ---------------------------------------------------------------------- assertEquals("Codehaus", project4.getOrganization().getName()); // ---------------------------------------------------------------------- // Value taken from super model // ---------------------------------------------------------------------- assertEquals("4.0.0", project4.getModelVersion()); Build build = project4.getBuild(); List plugins = build.getPlugins(); Map validPluginCounts = new HashMap(); String testPluginArtifactId = "maven-compiler-plugin"; // this is the plugin we're looking for. validPluginCounts.put(testPluginArtifactId, 0); // these are injected if -DperformRelease=true validPluginCounts.put("maven-deploy-plugin", 0); validPluginCounts.put("maven-javadoc-plugin", 0); validPluginCounts.put("maven-source-plugin", 0); Plugin testPlugin = null; for (Iterator it = plugins.iterator(); it.hasNext(); ) { Plugin plugin = (Plugin) it.next(); String pluginArtifactId = plugin.getArtifactId(); if (!validPluginCounts.containsKey(pluginArtifactId)) { fail("Illegal plugin found: " + pluginArtifactId); } else { if (pluginArtifactId.equals(testPluginArtifactId)) { testPlugin = plugin; } Integer count = (Integer) validPluginCounts.get(pluginArtifactId); if (count.intValue() > 0) { fail("Multiple copies of plugin: " + pluginArtifactId + " found in POM."); } else { count = count.intValue() + 1; validPluginCounts.put(pluginArtifactId, count); } } } List executions = testPlugin.getExecutions(); assertEquals(1, executions.size()); }
private static boolean isMultiModuleReleasePlugin(Plugin plugin) { return plugin.getGroupId().equals("com.github.danielflower.mavenplugins") && plugin.getArtifactId().equals("multi-module-maven-release-plugin"); }