org.apache.maven.model.Build Java Examples
The following examples show how to use
org.apache.maven.model.Build.
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: GitVersioningModelProcessor.java From maven-git-versioning-extension with MIT License | 6 votes |
private void addBuildPlugin(Model model, boolean updatePomOption) { logger.debug(model.getArtifactId() + " temporary add build plugin"); Plugin plugin = asPlugin(); PluginExecution execution = new PluginExecution(); execution.setId(GOAL); execution.getGoals().add(GOAL); plugin.getExecutions().add(execution); if (model.getBuild() == null) { model.setBuild(new Build()); } model.getBuild().getPlugins().add(plugin); // set plugin properties model.getProperties().setProperty(propertyKeyPrefix + propertyKeyUpdatePom, Boolean.toString(updatePomOption)); }
Example #2
Source File: InitializeMojoTest.java From vertx-maven-plugin with Apache License 2.0 | 6 votes |
private InitializeMojo createMojoInstance() throws PlexusContainerException { InitializeMojo mojo = new InitializeMojo(); mojo.project = new MavenProject(); mojo.repositorySystem = new DefaultRepositorySystem(); mojo.repositorySystemSession = new DefaultRepositorySystemSession(); mojo.buildPluginManager = new DefaultBuildPluginManager(); mojo.container = new DefaultPlexusContainer(new DefaultContainerConfiguration()); mojo.mavenSession = new MavenSession(mojo.container, mojo.repositorySystemSession, new DefaultMavenExecutionRequest(), new DefaultMavenExecutionResult()); mojo.lifecycleExecutor = new DefaultLifecycleExecutor(); mojo.scmManager = new DefaultScmManager(); mojo.remoteRepositories = Collections.emptyList(); mojo.projectBuildDir = OUT.getAbsolutePath(); Build build = new Build(); build.setOutputDirectory(OUT.getAbsolutePath()); mojo.project.setBuild(build); return mojo; }
Example #3
Source File: DistributionEnforcingManipulatorTest.java From pom-manipulation-ext with Apache License 2.0 | 6 votes |
@Test public void projectUnchangedWhenModeIsNone() throws Exception { final Plugin plugin = new Plugin(); plugin.setGroupId( MAVEN_PLUGIN_GROUPID ); plugin.setArtifactId( MAVEN_DEPLOY_ARTIFACTID ); plugin.setConfiguration( simpleSkipConfig( true ) ); final Build build = new Build(); build.addPlugin( plugin ); final Model model = new Model(); model.setModelVersion( "4.0.0" ); model.setGroupId( "org.foo" ); model.setArtifactId( "bar" ); model.setVersion( "1" ); model.setBuild( build ); applyTest( none, model, null ); }
Example #4
Source File: DisplayDependencyUpdatesMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
private static Set<Dependency> extractPluginDependenciesFromPluginsInPluginManagement( Build build ) { Set<Dependency> result = new TreeSet<>( new DependencyComparator() ); if ( build.getPluginManagement() != null ) { for ( Plugin plugin : build.getPluginManagement().getPlugins() ) { if ( plugin.getDependencies() != null && !plugin.getDependencies().isEmpty() ) { for ( Dependency pluginDependency : plugin.getDependencies() ) { result.add( pluginDependency ); } } } } return result; }
Example #5
Source File: DeploymentHelper.java From netbeans with Apache License 2.0 | 6 votes |
private static boolean touchCoSTimeStamp(RunConfig rc, long stamp) { if (rc.getProject() == null) { return false; } Build build = rc.getMavenProject().getBuild(); if (build == null || build.getOutputDirectory() == null) { return false; } File fl = new File(build.getOutputDirectory()); fl = FileUtil.normalizeFile(fl); if (!fl.exists()) { //the project was not built return false; } File check = new File(fl, NB_COS); if (!check.exists()) { try { return check.createNewFile(); } catch (IOException ex) { return false; } } return check.setLastModified(stamp); }
Example #6
Source File: DistributionEnforcingManipulatorTest.java From pom-manipulation-ext with Apache License 2.0 | 6 votes |
@Test public void projectDeploySkipTurnedOffWhenModeIsOff() throws Exception { final Plugin plugin = new Plugin(); plugin.setGroupId( MAVEN_PLUGIN_GROUPID ); plugin.setArtifactId( MAVEN_DEPLOY_ARTIFACTID ); plugin.setConfiguration( simpleSkipConfig( true ) ); final Build build = new Build(); build.addPlugin( plugin ); final Model model = new Model(); model.setModelVersion( "4.0.0" ); model.setGroupId( "org.foo" ); model.setArtifactId( "bar" ); model.setVersion( "1" ); model.setBuild( build ); applyTest( off, model, model ); assertSkip( model, null ); }
Example #7
Source File: CosChecker.java From netbeans with Apache License 2.0 | 6 votes |
private static File getCoSFile(MavenProject mp, boolean test) { if (mp == null) { return null; } Build build = mp.getBuild(); if (build == null) { return null; } String path = test ? build.getTestOutputDirectory() : build.getOutputDirectory(); if (path == null) { return null; } File fl = new File(path); fl = FileUtil.normalizeFile(fl); return new File(fl, NB_COS); }
Example #8
Source File: MainInstrumentMojoTest.java From coroutines with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void mustNotThrowExceptionWhenDirectoryDoesntExist() throws Exception { File mainDir = null; try { // create a folder and delete it right away mainDir = Files.createTempDirectory(getClass().getSimpleName()).toFile(); File fakeFolder = new File(mainDir, "DOESNOTEXIST"); // mock Mockito.when(mavenProject.getCompileClasspathElements()).thenReturn(Collections.emptyList()); Build build = Mockito.mock(Build.class); Mockito.when(mavenProject.getBuild()).thenReturn(build); Mockito.when(build.getOutputDirectory()).thenReturn(fakeFolder.getAbsolutePath()); // execute plugin fixture.execute(); } finally { if (mainDir != null) { FileUtils.deleteDirectory(mainDir); } } }
Example #9
Source File: A_ModuleGenerator.java From deadcode4j with Apache License 2.0 | 6 votes |
private MavenProject givenMavenProject(String projectId) { MavenProject mavenProject = new MavenProject(); mavenProject.setGroupId("de.is24.junit"); mavenProject.setArtifactId(projectId); mavenProject.setVersion("42"); mavenProject.getProperties().setProperty("project.build.sourceEncoding", "UTF-8"); ArtifactStub projectArtifact = new ArtifactStub(); projectArtifact.setGroupId("de.is24.junit"); projectArtifact.setArtifactId(projectId); projectArtifact.setVersion("42"); mavenProject.setArtifact(projectArtifact); Build build = new Build(); build.setOutputDirectory(tempFileRule.getTempFile().getParent()); mavenProject.setBuild(build); return mavenProject; }
Example #10
Source File: DetectFractionsCommand.java From thorntail-addon with Eclipse Public License 1.0 | 6 votes |
private DirectoryResource getTargetDirectory(Project project) { MavenFacet mavenFacet = project.getFacet(MavenFacet.class); Build build = mavenFacet.getModel().getBuild(); String targetFolderName; if (build != null && build.getOutputDirectory() != null) { targetFolderName = mavenFacet.resolveProperties(build.getOutputDirectory()); } else { targetFolderName = "target" + File.separator + "classes"; } DirectoryResource projectRoot = project.getRoot().reify(DirectoryResource.class); return projectRoot.getChildDirectory(targetFolderName); }
Example #11
Source File: TestInstrumentMojoTest.java From coroutines with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void mustNotThrowExceptionWhenDirectoryDoesntExist() throws Exception { File testDir = null; try { // create a folder and delete it right away testDir = Files.createTempDirectory(getClass().getSimpleName()).toFile(); File fakeFolder = new File(testDir, "DOESNOTEXIST"); // mock Mockito.when(mavenProject.getTestClasspathElements()).thenReturn(Collections.emptyList()); Build build = Mockito.mock(Build.class); Mockito.when(mavenProject.getBuild()).thenReturn(build); Mockito.when(build.getTestOutputDirectory()).thenReturn(fakeFolder.getAbsolutePath()); // execute plugin fixture.execute(); } finally { if (testDir != null) { FileUtils.deleteDirectory(testDir); } } }
Example #12
Source File: RequirePropertyDivergesTest.java From extra-enforcer-rules with Apache License 2.0 | 6 votes |
/** * Test of execute method, of class RequirePropertyDiverges. */ @Test public void testExecuteInParentWithConfigurationInExecution() throws EnforcerRuleException { RequirePropertyDiverges mockInstance = createMockRule(); final MavenProject project = createMavenProject( "company", "company-parent-pom" ); final Build build = new Build(); build.setPluginManagement( new PluginManagement() ); final Plugin plugin = newPlugin( "org.apache.maven.plugins", "maven-enforcer-plugin", "1.0" ); final Xpp3Dom configuration = createPluginConfiguration(); PluginExecution pluginExecution = new PluginExecution(); pluginExecution.setConfiguration( configuration ); plugin.addExecution( pluginExecution ); build.addPlugin( plugin ); project.getOriginalModel().setBuild( build ); setUpHelper(project, "parentValue"); mockInstance.execute( helper ); }
Example #13
Source File: RequirePropertyDivergesTest.java From extra-enforcer-rules with Apache License 2.0 | 6 votes |
/** * Test of execute method, of class RequirePropertyDiverges. */ @Test public void testExecuteInParentWithConfigurationInPluginManagement() throws EnforcerRuleException { RequirePropertyDiverges mockInstance = createMockRule(); final MavenProject project = createMavenProject( "company", "company-parent-pom" ); final Build build = new Build(); // create pluginManagement final Plugin pluginInManagement = newPlugin( "org.apache.maven.plugins", "maven-enforcer-plugin", "1.0"); final Xpp3Dom configuration = createPluginConfiguration(); pluginInManagement.setConfiguration( configuration ); final PluginManagement pluginManagement = new PluginManagement(); pluginManagement.addPlugin( pluginInManagement ); build.setPluginManagement( pluginManagement ); // create plugins final Plugin pluginInPlugins = newPlugin( "org.apache.maven.plugins", "maven-enforcer-plugin", "1.0"); build.addPlugin( pluginInPlugins ); // add build project.getOriginalModel().setBuild( build ); //project.getOriginalModel().setBuild( build ); setUpHelper( project, "parentValue" ); mockInstance.execute( helper ); }
Example #14
Source File: BasePitMojoTest.java From pitest with Apache License 2.0 | 6 votes |
@Override protected void setUp() throws Exception { super.setUp(); MockitoAnnotations.initMocks(this); this.classPath = new ArrayList<>(FCollection.map( ClassPath.getClassPathElementsAsFiles(), fileToString())); when(this.project.getTestClasspathElements()).thenReturn(this.classPath); when(this.project.getPackaging()).thenReturn("jar"); final Build build = new Build(); build.setOutputDirectory(""); when(this.project.getBuild()).thenReturn(build); when(this.plugins.findToolClasspathPlugins()).thenReturn( Collections.emptyList()); when(this.plugins.findClientClasspathPlugins()).thenReturn( Collections.emptyList()); }
Example #15
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 #16
Source File: YangToSourcesProcessorTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void test() throws Exception { final File file = new File(getClass().getResource("/yang").getFile()); final File excludedYang = new File(getClass().getResource("/yang/excluded-file.yang").getFile()); final String path = file.getPath(); final CodeGeneratorArg codeGeneratorArg = new CodeGeneratorArg(GeneratorMock.class.getName(), "target/YangToSourcesProcessorTest-outputBaseDir"); final List<CodeGeneratorArg> codeGenerators = ImmutableList.of(codeGeneratorArg); final MavenProject mvnProject = Mockito.mock(MavenProject.class); final Build build = new Build(); Mockito.when(mvnProject.getBuild()).thenReturn(build); final boolean dependencies = true; final YangToSourcesProcessor proc = new YangToSourcesProcessor(file, ImmutableList.of(excludedYang), codeGenerators, mvnProject, dependencies, YangProvider.getInstance()); Assert.assertNotNull(proc); proc.execute(); }
Example #17
Source File: RequirePropertyDiverges.java From extra-enforcer-rules with Apache License 2.0 | 6 votes |
/** * Returns the rule configurations from the <tt>pluginManagement</tt> as well * as the <tt>plugins</tt> section. * * @param build the build to inspect. * @return configuration of the rules, may be an empty list. */ final List<Xpp3Dom> getRuleConfigurations( final Build build ) { @SuppressWarnings( "unchecked" ) final Map<String, Plugin> plugins = build.getPluginsAsMap(); final List<Xpp3Dom> ruleConfigurationsForPlugins = getRuleConfigurations( plugins ); final PluginManagement pluginManagement = build.getPluginManagement(); if ( pluginManagement != null ) { @SuppressWarnings( "unchecked" ) final Map<String, Plugin> pluginsFromManagementAsMap = pluginManagement.getPluginsAsMap(); List<Xpp3Dom> ruleConfigurationsFromManagement = getRuleConfigurations( pluginsFromManagementAsMap ); ruleConfigurationsForPlugins.addAll( ruleConfigurationsFromManagement ); } return ruleConfigurationsForPlugins; }
Example #18
Source File: RequirePropertyDiverges.java From extra-enforcer-rules with Apache License 2.0 | 6 votes |
/** * Finds the ancestor project which defines the rule. * * @param project to inspect * @return the defining ancestor project. */ final MavenProject findDefiningParent( final MavenProject project ) { final Xpp3Dom invokingRule = createInvokingRuleDom(); MavenProject parent = project; while ( parent != null ) { final Model model = parent.getOriginalModel(); final Build build = model.getBuild(); if ( build != null ) { final List<Xpp3Dom> rules = getRuleConfigurations( build ); if ( isDefiningProject( rules, invokingRule ) ) { break; } } parent = parent.getParent(); } return parent; }
Example #19
Source File: CheckPluginDependencyVersions.java From unleash-maven-plugin with Eclipse Public License 1.0 | 6 votes |
private Multimap<ArtifactCoordinates, ArtifactCoordinates> getSnapshotsFromManagement(MavenProject project, PomPropertyResolver propertyResolver) { this.log.debug("\t\tChecking managed plugins"); Multimap<ArtifactCoordinates, ArtifactCoordinates> result = HashMultimap.create(); Build build = project.getBuild(); if (build != null) { PluginManagement pluginManagement = build.getPluginManagement(); if (pluginManagement != null) { for (Plugin plugin : pluginManagement.getPlugins()) { Collection<Dependency> snapshots = Collections2.filter(plugin.getDependencies(), new IsSnapshotDependency(propertyResolver)); if (!snapshots.isEmpty()) { result.putAll(PluginToCoordinates.INSTANCE.apply(plugin), Collections2.transform(snapshots, DependencyToCoordinates.INSTANCE)); } } } } return result; }
Example #20
Source File: CheckPluginDependencyVersions.java From unleash-maven-plugin with Eclipse Public License 1.0 | 6 votes |
private Multimap<ArtifactCoordinates, ArtifactCoordinates> getSnapshots(MavenProject project, PomPropertyResolver propertyResolver) { this.log.debug("\t\tChecking direct plugin references"); Multimap<ArtifactCoordinates, ArtifactCoordinates> result = HashMultimap.create(); Build build = project.getBuild(); if (build != null) { for (Plugin plugin : build.getPlugins()) { Collection<Dependency> snapshots = Collections2.filter(plugin.getDependencies(), new IsSnapshotDependency(propertyResolver)); if (!snapshots.isEmpty()) { result.putAll(PluginToCoordinates.INSTANCE.apply(plugin), Collections2.transform(snapshots, DependencyToCoordinates.INSTANCE)); } } } return result; }
Example #21
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 #22
Source File: RequirePropertyDivergesTest.java From extra-enforcer-rules with Apache License 2.0 | 5 votes |
@Test public void testProjectWithoutEnforcer() { final Build build = new Build(); //build.setPluginManagement( new PluginManagement() ); instance.getRuleConfigurations( build ); }
Example #23
Source File: BuildFrontendMojoTest.java From flow with Apache License 2.0 | 5 votes |
static void setProject(AbstractMojo mojo, File baseFolder) throws Exception { Build buildMock = mock(Build.class); when(buildMock.getFinalName()).thenReturn("finalName"); MavenProject project = mock(MavenProject.class); when(project.getBasedir()).thenReturn(baseFolder); when(project.getBuild()).thenReturn(buildMock); when(project.getRuntimeClasspathElements()).thenReturn(getClassPath()); ReflectionUtils.setVariableValueInObject(mojo, "project", project); }
Example #24
Source File: TestInstrumentMojoTest.java From coroutines with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void mustInstrumentClasses() throws Exception { byte[] classContent = readZipFromResource("NormalInvokeTest.zip").get("NormalInvokeTest.class"); File testDir = null; try { // write out testDir = Files.createTempDirectory(getClass().getSimpleName()).toFile(); File testClass = new File(testDir, "NormalInvokeTest.class"); FileUtils.writeByteArrayToFile(testClass, classContent); // mock Mockito.when(mavenProject.getTestClasspathElements()).thenReturn(Collections.emptyList()); Build build = Mockito.mock(Build.class); Mockito.when(mavenProject.getBuild()).thenReturn(build); Mockito.when(build.getTestOutputDirectory()).thenReturn(testDir.getAbsolutePath()); // execute plugin fixture.execute(); // read back in byte[] modifiedTestClassContent = FileUtils.readFileToByteArray(testClass); // test assertTrue(modifiedTestClassContent.length > classContent.length); } finally { if (testDir != null) { FileUtils.deleteDirectory(testDir); } } }
Example #25
Source File: PomProperty.java From flatten-maven-plugin with Apache License 2.0 | 5 votes |
@Override public void set( Model model, PluginManagement value ) { if ( model.getBuild() == null ) { model.setBuild( new Build() ); } model.getBuild().setPluginManagement( value ); }
Example #26
Source File: CreateMavenBundlePom.java From tesb-studio-se with Apache License 2.0 | 5 votes |
/** * skip depoly phase in publich to cloud in parent pom, enable in nexus. */ private Profile addProfileForCloud() { Profile deployCloudProfile = new Profile(); deployCloudProfile.setId("deploy-cloud"); Activation deployCloudActivation = new Activation(); ActivationProperty activationProperty = new ActivationProperty(); activationProperty.setName("!altDeploymentRepository"); deployCloudActivation.setProperty(activationProperty); deployCloudProfile.setActivation(deployCloudActivation); deployCloudProfile.setBuild(new Build()); deployCloudProfile.getBuild().addPlugin(addSkipDeployFeatureMavenPlugin()); return deployCloudProfile; }
Example #27
Source File: MainInstrumentMojoTest.java From coroutines with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void mustInstrumentClasses() throws Exception { byte[] classContent = readZipFromResource("NormalInvokeTest.zip").get("NormalInvokeTest.class"); File mainDir = null; try { // write out mainDir = Files.createTempDirectory(getClass().getSimpleName()).toFile(); File mainClass = new File(mainDir, "NormalInvokeTest.class"); FileUtils.writeByteArrayToFile(mainClass, classContent); // mock Mockito.when(mavenProject.getCompileClasspathElements()).thenReturn(Collections.emptyList()); Build build = Mockito.mock(Build.class); Mockito.when(mavenProject.getBuild()).thenReturn(build); Mockito.when(build.getOutputDirectory()).thenReturn(mainDir.getAbsolutePath()); // execute plugin fixture.execute(); // read back in byte[] modifiedMainClassContent = FileUtils.readFileToByteArray(mainClass); // test assertTrue(modifiedMainClassContent.length > classContent.length); } finally { if (mainDir != null) { FileUtils.deleteDirectory(mainDir); } } }
Example #28
Source File: CreateMavenDataServicePom.java From tesb-studio-se with Apache License 2.0 | 5 votes |
/** * DOC skip depoly phase in publich to cloud in parent pom, enable in nexus. */ private Profile addProfileForCloud() { Profile deployCloudProfile = new Profile(); deployCloudProfile.setId("deploy-cloud"); Activation deployCloudActivation = new Activation(); ActivationProperty activationProperty = new ActivationProperty(); activationProperty.setName("!altDeploymentRepository"); deployCloudActivation.setProperty(activationProperty); deployCloudProfile.setActivation(deployCloudActivation); deployCloudProfile.setBuild(new Build()); deployCloudProfile.getBuild().addPlugin(addSkipDeployFeatureMavenPlugin()); return deployCloudProfile; }
Example #29
Source File: AbstractRunMojoTest.java From app-maven-plugin with Apache License 2.0 | 5 votes |
@Before public void setUp() { Build build = Mockito.mock(Build.class); Mockito.when(mavenProject.getBuild()).thenReturn(build); Mockito.when(build.getDirectory()).thenReturn("fake-build-dir"); Mockito.when(build.getFinalName()).thenReturn("fake-final-name"); }
Example #30
Source File: RequirePropertyDivergesTest.java From extra-enforcer-rules with Apache License 2.0 | 5 votes |
private MavenProject createParentProject() { final MavenProject project = createMavenProject( "company", "company-parent-pom" ); final Build build = new Build(); build.setPluginManagement( new PluginManagement() ); final Plugin plugin = newPlugin( "org.apache.maven.plugins", "maven-enforcer-plugin", "1.0"); final Xpp3Dom configuration = createPluginConfiguration(); plugin.setConfiguration( configuration ); build.addPlugin( plugin ); project.getOriginalModel().setBuild( build ); return project; }