org.apache.maven.project.MavenProject Java Examples
The following examples show how to use
org.apache.maven.project.MavenProject.
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: MavenUtil.java From jkube with Eclipse Public License 2.0 | 6 votes |
/** * Returns the plugin with the given groupId (if present) and artifactId. * * @param project MavenProject of project * @param groupId group id * @param artifactId artifact id * @return return Plugin object for the specific plugin */ public static org.apache.maven.model.Plugin getPlugin(MavenProject project, String groupId, String artifactId) { if (artifactId == null) { throw new IllegalArgumentException("artifactId cannot be null"); } List<org.apache.maven.model.Plugin> plugins = project.getBuildPlugins(); if (plugins != null) { for (org.apache.maven.model.Plugin plugin : plugins) { boolean matchesArtifactId = artifactId.equals(plugin.getArtifactId()); boolean matchesGroupId = groupId == null || groupId.equals(plugin.getGroupId()); if (matchesGroupId && matchesArtifactId) { return plugin; } } } return null; }
Example #2
Source File: MavenSourcesImpl.java From netbeans with Apache License 2.0 | 6 votes |
@Messages({ "SG_Sources=Source Packages", "SG_Test_Sources=Test Packages" }) private void checkChanges(boolean fireChanges, boolean checkAlsoNonJavaStuff) { boolean changed = false; synchronized (lock) { NbMavenProjectImpl project = project(); MavenProject mp = project.getOriginalMavenProject(); NbMavenProject watcher = project.getProjectWatcher(); File folder = FileUtilities.convertStringToFile(mp.getBuild().getSourceDirectory()); changed = changed | checkSourceGroupCache(folder, NAME_SOURCE, SG_Sources(), javaGroup, watcher); folder = FileUtilities.convertStringToFile(mp.getBuild().getTestSourceDirectory()); changed = changed | checkSourceGroupCache(folder, NAME_TESTSOURCE, SG_Test_Sources(), javaGroup, watcher); changed = changed | checkGeneratedGroupsCache(); if (checkAlsoNonJavaStuff) { changed = changed | checkOtherGroupsCache(project.getOtherRoots(false), false); changed = changed | checkOtherGroupsCache(project.getOtherRoots(true), true); } } if (changed) { if (fireChanges) { cs.fireChange(); } } }
Example #3
Source File: DockerAssemblyManagerTest.java From docker-maven-plugin with Apache License 2.0 | 6 votes |
@Test public void assemblyFiles(@Injectable final MojoParameters mojoParams, @Injectable final MavenProject project, @Injectable final Assembly assembly) throws AssemblyFormattingException, ArchiveCreationException, InvalidAssemblerConfigurationException, MojoExecutionException, AssemblyReadException, IllegalAccessException { ReflectionUtils.setVariableValueInObject(assemblyManager, "trackArchiver", trackArchiver); new Expectations() {{ mojoParams.getOutputDirectory(); result = "target/"; times = 3; mojoParams.getProject(); project.getBasedir(); result = "."; assemblyReader.readAssemblies((AssemblerConfigurationSource) any); result = Arrays.asList(assembly); }}; BuildImageConfiguration buildConfig = createBuildConfig(); assemblyManager.getAssemblyFiles("testImage", buildConfig, mojoParams, new AnsiLogger(new SystemStreamLog(),true,"build")); }
Example #4
Source File: ExternalVersionExtension.java From maven-external-version with Apache License 2.0 | 6 votes |
private String getNewVersion( ExternalVersionStrategy strategy, MavenProject mavenProject ) throws ExternalVersionException { // snapshot detection against the old version. boolean isSnapshot = ArtifactUtils.isSnapshot( mavenProject.getVersion() ); // lookup the new version String newVersion = strategy.getVersion( mavenProject ); if ( newVersion != null ) { newVersion = newVersion.trim(); } boolean isNewSnapshot = ArtifactUtils.isSnapshot( newVersion ); // make sure we still have a SNAPSHOT if we had one previously. if ( isSnapshot && !isNewSnapshot ) { newVersion = newVersion + "-SNAPSHOT"; } return newVersion; }
Example #5
Source File: PitAggregationMojo.java From pitest with Apache License 2.0 | 6 votes |
@Override List<MavenProject> findDependencies() { final List<MavenProject> result = new ArrayList<>(); final List<String> scopeList = Arrays.asList(Artifact.SCOPE_COMPILE, Artifact.SCOPE_RUNTIME, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_TEST); for (final Object dependencyObject : getProject().getDependencies()) { final Dependency dependency = (Dependency) dependencyObject; if (scopeList.contains(dependency.getScope())) { final MavenProject project = findProjectFromReactor(dependency); if (project != null) { result.add(project); } } } return result; }
Example #6
Source File: LooseEarApplication.java From ci.maven with Apache License 2.0 | 6 votes |
public Element addRarModule(MavenProject proj) throws Exception { Element rarArchive = config.addArchive(getModuleUri(proj)); config.addDir(rarArchive, getRarSourceDirectory(proj), "/"); // get raXmlFile optional rar plugin parameter String path = MavenProjectUtil.getPluginConfiguration(proj, "org.apache.maven.plugins", "maven-rar-plugin", "raXmlFile"); if (path != null && !path.isEmpty()) { File raXmlFile = new File(path); config.addFile(rarArchive, raXmlFile, "/META-INF/ra.xml"); } // add Manifest file File manifestFile = MavenProjectUtil.getManifestFile(proj, "maven-rar-plugin"); addManifestFileWithParent(rarArchive, manifestFile); return rarArchive; }
Example #7
Source File: MavenSkipProcessor.java From dew with Apache License 2.0 | 6 votes |
/** * Disabled default behavior. * * @param project the project */ public static void disabledDefaultBehavior(MavenProject project) { project.getProperties().put("dew.devops.skip", "true"); project.getProperties().put("maven.javadoc.skip", "true"); project.getProperties().put("maven.source.skip", "true"); project.getProperties().put("checkstyle.skip", "true"); project.getProperties().put("assembly.skipAssembly", "true"); project.getProperties().put("mdep.analyze.skip", "true"); project.getProperties().put("maven.main.skip", "true"); project.getProperties().put("gpg.skip", "true"); project.getProperties().put("maven.war.skip", "true"); project.getProperties().put("maven.resources.skip", "true"); project.getProperties().put("maven.test.skip", "true"); project.getProperties().put("maven.install.skip", "true"); project.getProperties().put("maven.deploy.skip", "true"); project.getProperties().put("maven.site.skip", "true"); }
Example #8
Source File: UnchangedProjectsRemoverSelectedProjectsTest.java From gitflow-incremental-builder with MIT License | 6 votes |
@Test public void moduleBChanged_makeBoth() throws GitAPIException, IOException { MavenProject moduleB = addModuleMock(AID_MODULE_B, true); MavenProject moduleC = addModuleMock(AID_MODULE_C, false); setUpstreamProjects(moduleC, moduleB, moduleA); setDownstreamProjects(moduleB, moduleC); setDownstreamProjects(moduleA, moduleB, moduleC); setProjectSelections(moduleB); when(mavenExecutionRequestMock.getMakeBehavior()).thenReturn(MavenExecutionRequest.REACTOR_MAKE_BOTH); underTest.act(); verify(mavenSessionMock).setProjects(Arrays.asList(moduleB, moduleC)); assertProjectPropertiesEqual(moduleB, Collections.emptyMap()); assertProjectPropertiesEqual(moduleC, Collections.emptyMap()); }
Example #9
Source File: MavenUtilTest.java From jkube with Eclipse Public License 2.0 | 6 votes |
private MavenProject getMavenProject() { MavenProject mavenProject = new MavenProject(); mavenProject.setName("testProject"); mavenProject.setGroupId("org.eclipse.jkube"); mavenProject.setArtifactId("test-project"); mavenProject.setVersion("0.1.0"); mavenProject.setDescription("test description"); Build build = new Build(); build.setOutputDirectory("./target"); build.setDirectory("."); mavenProject.setBuild(build); DistributionManagement distributionManagement = new DistributionManagement(); Site site = new Site(); site.setUrl("https://www.eclipse.org/jkube/"); distributionManagement.setSite(site); mavenProject.setDistributionManagement(distributionManagement); return mavenProject; }
Example #10
Source File: AbstractVersionsDependencyUpdaterMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
protected String toString( MavenProject project ) { StringBuilder buf = new StringBuilder(); buf.append( project.getGroupId() ); buf.append( ':' ); buf.append( project.getArtifactId() ); if ( project.getVersion() != null && project.getVersion().length() > 0 ) { buf.append( ":" ); buf.append( project.getVersion() ); } return buf.toString(); }
Example #11
Source File: GoogleFormatterMojo.java From googleformatter-maven-plugin with Apache License 2.0 | 6 votes |
private Set<File> filterUnchangedFiles(Set<File> originalFiles) throws MojoExecutionException { MavenProject topLevelProject = session.getTopLevelProject(); try { if (topLevelProject.getScm().getConnection() == null && topLevelProject.getScm().getDeveloperConnection() == null) { throw new MojoExecutionException( "You must supply at least one of scm.connection or scm.developerConnection in your POM file if you " + "specify the filterModified or filter.modified option."); } String connectionUrl = MoreObjects.firstNonNull(topLevelProject.getScm().getConnection(), topLevelProject.getScm().getDeveloperConnection()); ScmRepository repository = scmManager.makeScmRepository(connectionUrl); ScmFileSet scmFileSet = new ScmFileSet(topLevelProject.getBasedir()); String basePath = topLevelProject.getBasedir().getAbsoluteFile().getPath(); List<String> changedFiles = scmManager.status(repository, scmFileSet).getChangedFiles().stream() .map(f -> new File(basePath, f.getPath()).toString()) .collect(Collectors.toList()); return originalFiles.stream().filter(f -> changedFiles.contains(f.getPath())).collect(Collectors.toSet()); } catch (ScmException e) { throw new MojoExecutionException(e.getMessage(), e); } }
Example #12
Source File: MavenUtils.java From developer-studio with Apache License 2.0 | 6 votes |
public static void addMavenBpelPlugin(MavenProject mavenProject){ Plugin plugin; PluginExecution pluginExecution; plugin = MavenUtils.createPluginEntry(mavenProject, GROUP_ID_ORG_WSO2_MAVEN, ARTIFACT_ID_MAVEN_BPEL_PLUGIN, WSO2MavenPluginVersions.getPluginVersion(ARTIFACT_ID_MAVEN_BPEL_PLUGIN), true); // FIXME : remove hard-coded version value (cannot use // org.wso2.developerstudio.eclipse.capp.maven.utils.MavenConstants // due to cyclic reference) // pluginExecution=new PluginExecution(); // pluginExecution.addGoal("bpel"); // pluginExecution.setPhase("package"); // pluginExecution.setId("bpel"); // plugin.addExecution(pluginExecution) mavenProject.getModel().addProperty(PROPERTY_CAPP_TYPE, "bpel/workflow"); }
Example #13
Source File: InstallDeployTest.java From takari-lifecycle with Eclipse Public License 1.0 | 6 votes |
private MavenSession newSession(MavenProject project, File localrepo, Properties properties) throws Exception { MavenExecutionRequest request = new DefaultMavenExecutionRequest(); MavenExecutionResult result = new DefaultMavenExecutionResult(); DefaultRepositorySystemSession repoSession = MavenRepositorySystemUtils.newSession(); LocalRepository localRepo = new LocalRepository(localrepo); repoSession.setLocalRepositoryManager(mojos.getContainer().lookup(LocalRepositoryManagerFactory.class, "simple").newInstance(repoSession, localRepo)); MavenSession session = new MavenSession(mojos.getContainer(), repoSession, request, result); List<MavenProject> projects = new ArrayList<>(); projects.add(project); for (String module : project.getModules()) { MavenProject moduleProject = readMavenProject(new File(project.getBasedir(), module), properties); moduleProject.setParent(project); projects.add(moduleProject); } session.setProjects(projects); return session; }
Example #14
Source File: DockerAssemblyManager.java From docker-maven-plugin with Apache License 2.0 | 6 votes |
private File ensureThatArtifactFileIsSet(MavenProject project) { Artifact artifact = project.getArtifact(); if (artifact == null) { return null; } File oldFile = artifact.getFile(); if (oldFile != null) { return oldFile; } Build build = project.getBuild(); if (build == null) { return null; } String finalName = build.getFinalName(); String target = build.getDirectory(); if (finalName == null || target == null) { return null; } File artifactFile = new File(target, finalName + "." + project.getPackaging()); if (artifactFile.exists() && artifactFile.isFile()) { setArtifactFile(project, artifactFile); } return null; }
Example #15
Source File: SimpleReactorReader.java From takari-lifecycle with Eclipse Public License 1.0 | 5 votes |
@Override public List<String> findVersions(Artifact artifact) { MavenProject project = getProject(artifact); if (project != null) { return Collections.singletonList(project.getVersion()); } Artifact _artifact = getArtifact(artifact); if (_artifact != null) { return Collections.singletonList(_artifact.getVersion()); } return null; }
Example #16
Source File: AbstractRepairMojo.java From repairnator with MIT License | 5 votes |
public List<File> getTestFolders() { Set<File> sourceFolder = new HashSet<>(); for (MavenProject mavenProject : reactorProjects) { File sourceDirectory = new File(mavenProject.getBuild().getTestSourceDirectory()); if (sourceDirectory.exists()) { sourceFolder.add(sourceDirectory); } } return new ArrayList<>(sourceFolder); }
Example #17
Source File: DefaultDescriptorsExtractor.java From james-project with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private Collection<JavaClass> javaClasses(MavenProject project) { JavaProjectBuilder builder = new JavaProjectBuilder(); for (String s : (Iterable<String>) project.getCompileSourceRoots()) { builder.addSourceTree(new File(s)); } return builder.getClasses(); }
Example #18
Source File: MavenLifecycleParticipantTest.java From gitflow-incremental-builder with MIT License | 5 votes |
@BeforeEach void before() { MavenProject mockTLProject = mock(MavenProject.class); when(mockTLProject.getProperties()).thenReturn(projectProperties); when(mavenSessionMock.getTopLevelProject()).thenReturn(mockTLProject); when(mavenSessionMock.getRequest()).thenReturn(mock(MavenExecutionRequest.class)); when(mavenSessionMock.getProjectDependencyGraph()).thenReturn(mock(ProjectDependencyGraph.class)); Whitebox.setInternalState(underTest, new Configuration.Provider(mavenSessionMock)); }
Example #19
Source File: MavenUtils.java From developer-studio with Apache License 2.0 | 5 votes |
public static MavenProject createMavenProject(String groupId, String artifactId, String version, String packagingType) { Model model = new Model(); model.setGroupId(groupId); model.setArtifactId(artifactId); model.setVersion(version); model.setModelVersion("4.0.0"); model.setName(artifactId); model.setDescription(artifactId); if (packagingType!=null){ model.setPackaging(packagingType); } return new MavenProject(model); }
Example #20
Source File: MavenProjectUtil.java From microprofile-sandbox with Apache License 2.0 | 5 votes |
public static String getJavaCompilerTargetVersion(MavenProject project) { // Check maven compiler properties Properties mavenProperties = project.getProperties(); for (Map.Entry<Object, Object> property : mavenProperties.entrySet()) { String propertyKey = property.getKey().toString(); String propertyValue = property.getValue().toString(); if (propertyKey.equals("maven.compiler.target") || propertyKey.equals("maven.compiler.release")) { return propertyValue; } } // Check maven-compiler-plugin release value String release = net.wasdev.wlp.maven.plugins.utils.MavenProjectUtil.getPluginConfiguration(project, "org.apache.maven.plugins", "maven-compiler-plugin", "release"); if (release != null) { return release; } // Check maven-compiler-plugin target value String target = net.wasdev.wlp.maven.plugins.utils.MavenProjectUtil.getPluginConfiguration(project, "org.apache.maven.plugins", "maven-compiler-plugin", "target"); if (target != null) { return target; } return ""; }
Example #21
Source File: DependenciesResolver.java From dew with Apache License 2.0 | 5 votes |
/** * Init. * * @param mavenSession the maven session */ public static void init(MavenSession mavenSession) { if (ExecuteOnceProcessor.executedCheck(DependenciesResolver.class)) { return; } try { DefaultProjectDependenciesResolver resolver = (DefaultProjectDependenciesResolver) mavenSession.getContainer() .lookup(ProjectDependenciesResolver.class.getName()); for (MavenProject mavenProject : mavenSession.getProjectDependencyGraph().getSortedProjects()) { mavenProject.setArtifacts(resolve(resolver, mavenProject, mavenSession)); } } catch (ComponentLookupException e) { throw new GlobalProcessException(e.getMessage(), e); } }
Example #22
Source File: DefaultMavenPom.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public DefaultMavenPom getEffectivePom() { DefaultMavenPom effectivePom = new DefaultMavenPom(null, this.scopeMappings, pomDependenciesConverter, fileResolver); try { effectivePom.setMavenProject((MavenProject) mavenProject.clone()); } catch (CloneNotSupportedException e) { throw new RuntimeException(e); } effectivePom.getDependencies().addAll(getGeneratedDependencies()); effectivePom.withXmlActions = withXmlActions; whenConfiguredActions.execute(effectivePom); return effectivePom; }
Example #23
Source File: AbstractVersionsStep.java From unleash-maven-plugin with Eclipse Public License 1.0 | 5 votes |
private void setProfilesReactorDependencyManagementVersion(MavenProject project, Document document) { List<Profile> profiles = this.rawModels.getUnchecked(project).getProfiles(); for (Profile profile : profiles) { final String dependenciesPath = "/profiles/profile[id[text()='" + profile.getId() + "']]/dependencyManagement"; DependencyManagement dependencyManagement = profile.getDependencyManagement(); if (dependencyManagement != null) { List<Dependency> dependencies = dependencyManagement.getDependencies(); for (Dependency dependency : dependencies) { trySetDependencyVersionFromReactorProjects(project, document, dependenciesPath, dependency); } } } }
Example #24
Source File: SchemaGeneratorMojoTest.java From jsonschema-generator with Apache License 2.0 | 5 votes |
/** * Execute the schema-generator plugin as define the the given pom file * * @param pomFile The pom file * @throws Exception In case of problems */ private void executePom(File pomFile) throws Exception { // Get the maven pom file content Xpp3Dom pomDom = Xpp3DomBuilder.build(new FileReader(pomFile)); PlexusConfiguration configuration = rule.extractPluginConfiguration("jsonschema-maven-plugin", pomDom); // Configure the Mojo SchemaGeneratorMojo myMojo = (SchemaGeneratorMojo) rule.lookupConfiguredMojo(new MavenProject(), "generate"); myMojo = (SchemaGeneratorMojo) rule.configureMojo(myMojo, configuration); // And execute myMojo.execute(); }
Example #25
Source File: JibHelper.java From component-runtime with Apache License 2.0 | 5 votes |
public void setProperties(final MavenProject project, final String versionProperty) { final String repo = repository == null ? "" : repository; project.getProperties().put(versionProperty, imageName); project.getProperties().put(versionProperty + ".repository", repo); project.getProperties().put(versionProperty + ".repositoryPrefixed", repo.isEmpty() ? "" : repo + '/'); project.getProperties().put(versionProperty + ".image", image); project.getProperties().put(versionProperty + ".version", tag); }
Example #26
Source File: AttachHelper.java From LicenseScout with Apache License 2.0 | 5 votes |
/** * Attaches generated report files as secondary artifacts. * * @param mavenProject * @param mavenProjectHelper * @param executionParameters * @param attachReportsClassifier the classifier value to for the attached report files * */ public static void attachReports(final MavenProject mavenProject, final MavenProjectHelper mavenProjectHelper, final ExecutionParameters executionParameters, final String attachReportsClassifier) { for (final ExecutionOutput output : executionParameters.getOutputs()) { final String artifactType = output.getType().getArtifactType(); final File artifactFile = new File(executionParameters.getOutputDirectory(), OutputFileHelper.getOutputFilename(output)); executionParameters.getLsLog().info("attaching artifact: " + artifactFile.getAbsolutePath()); mavenProjectHelper.attachArtifact(mavenProject, artifactType, attachReportsClassifier, artifactFile); } }
Example #27
Source File: MavenProjectSupplier.java From helidon-build-tools with Apache License 2.0 | 5 votes |
/** * Constructor. * * @param project The maven project. * @param session The maven session. * @param plugins The maven plugin manager. */ public MavenProjectSupplier(MavenProject project, MavenSession session, BuildPluginManager plugins) { MavenProjectConfigCollector.assertSupportedProject(session); this.project = project; this.session = requireNonNull(session); this.plugins = requireNonNull(plugins); this.firstBuild = new AtomicBoolean(true); }
Example #28
Source File: MavenUtil.java From jkube with Eclipse Public License 2.0 | 5 votes |
/** * Retrieves the URL used for documentation from the provided {@link MavenProject}. * * @param project MavenProject from which to retrieve the documentation URL * @return the documentation URL */ public static String getDocumentationUrl(MavenProject project) { while (project != null) { DistributionManagement distributionManagement = project.getDistributionManagement(); if (distributionManagement != null) { Site site = distributionManagement.getSite(); if (site != null) { return site.getUrl(); } } project = project.getParent(); } return null; }
Example #29
Source File: ScmMojo.java From pitest with Apache License 2.0 | 5 votes |
public ScmMojo(final RunPitStrategy executionStrategy, final ScmManager manager, Predicate<Artifact> filter, PluginServices plugins, boolean analyseLastCommit, Predicate<MavenProject> nonEmptyProjectCheck) { super(executionStrategy, filter, plugins, nonEmptyProjectCheck); this.manager = manager; this.analyseLastCommit = analyseLastCommit; }
Example #30
Source File: DisplayPluginUpdatesMojo.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
/** * Returns all the parent projects of the specified project, with the root project first. * * @param project The maven project to get the parents of * @return the parent projects of the specified project, with the root project first. * @throws org.apache.maven.plugin.MojoExecutionException if the super-pom could not be created. * @since 1.0-alpha-1 */ private List<MavenProject> getParentProjects( MavenProject project ) throws MojoExecutionException { List<MavenProject> parents = new ArrayList<>(); while ( project.getParent() != null ) { project = project.getParent(); parents.add( 0, project ); } return parents; }