From 8e891bbc0106dff50d814289aa0ae2c8f1366566 Mon Sep 17 00:00:00 2001 From: Saleh Mostafa Date: Mon, 13 Jul 2020 15:08:43 -0400 Subject: [PATCH 1/5] Remove first level transitive, provided scope dependencies and their subtrees --- src/it/mrm/parent-deps-1.1.pom | 17 +++++++ .../pom.xml | 37 ++++++++++++++ .../verify.groovy | 32 ++++++++++++ .../parent/pom.xml | 20 ++++++++ .../flatten-dependency-all-optional/pom.xml | 30 ++++++++++++ .../verify.groovy | 20 ++++++++ .../pom.xml | 28 +++++++++++ .../verify.groovy | 30 ++++++++++++ .../pom.xml | 28 +++++++++++ .../verify.groovy | 33 +++++++++++++ .../pom.xml | 27 ++++++++++ .../verify.groovy | 30 ++++++++++++ .../codehaus/mojo/flatten/FlattenMojo.java | 49 ++++++++++--------- 13 files changed, 359 insertions(+), 22 deletions(-) create mode 100644 src/it/mrm/parent-deps-1.1.pom create mode 100644 src/it/projects/flatten-dependency-all-depmgnt-provided-transitive/pom.xml create mode 100644 src/it/projects/flatten-dependency-all-depmgnt-provided-transitive/verify.groovy create mode 100644 src/it/projects/flatten-dependency-all-optional/parent/pom.xml create mode 100644 src/it/projects/flatten-dependency-all-optional/pom.xml create mode 100644 src/it/projects/flatten-dependency-all-optional/verify.groovy create mode 100644 src/it/projects/flatten-dependency-all-provided-children/pom.xml create mode 100644 src/it/projects/flatten-dependency-all-provided-children/verify.groovy create mode 100644 src/it/projects/flatten-dependency-all-provided-direct/pom.xml create mode 100644 src/it/projects/flatten-dependency-all-provided-direct/verify.groovy create mode 100644 src/it/projects/flatten-dependency-all-provided-transitive/pom.xml create mode 100644 src/it/projects/flatten-dependency-all-provided-transitive/verify.groovy diff --git a/src/it/mrm/parent-deps-1.1.pom b/src/it/mrm/parent-deps-1.1.pom new file mode 100644 index 00000000..8142f76a --- /dev/null +++ b/src/it/mrm/parent-deps-1.1.pom @@ -0,0 +1,17 @@ + + 4.0.0 + org.codehaus.mojo.flatten.its + parent-deps + 1.1 + pom + + + + + org.codehaus.mojo.flatten.its + dep + 1.1 + provided + + + \ No newline at end of file diff --git a/src/it/projects/flatten-dependency-all-depmgnt-provided-transitive/pom.xml b/src/it/projects/flatten-dependency-all-depmgnt-provided-transitive/pom.xml new file mode 100644 index 00000000..309ce9d3 --- /dev/null +++ b/src/it/projects/flatten-dependency-all-depmgnt-provided-transitive/pom.xml @@ -0,0 +1,37 @@ + + 4.0.0 + org.codehaus.mojo.flatten.its + flatten-dependency-all-depmgnt-provided-transitive + 0.0.1-SNAPSHOT + + + + + org.codehaus.mojo.flatten.its + dep + 1.1 + provided + + + + + + + org.codehaus.mojo.flatten.its + parent-deps + 1 + + + + + + + org.codehaus.mojo + flatten-maven-plugin + + all + + + + + \ No newline at end of file diff --git a/src/it/projects/flatten-dependency-all-depmgnt-provided-transitive/verify.groovy b/src/it/projects/flatten-dependency-all-depmgnt-provided-transitive/verify.groovy new file mode 100644 index 00000000..13dab1ff --- /dev/null +++ b/src/it/projects/flatten-dependency-all-depmgnt-provided-transitive/verify.groovy @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +File originalPom = new File( basedir, 'pom.xml' ) +assert originalPom.exists() + +def originalProject = new XmlSlurper().parse( originalPom ) +assert 1 == originalProject.dependencies.size() + +File flattendPom = new File( basedir, '.flattened-pom.xml' ) +assert flattendPom.exists() + +def flattendProject = new XmlSlurper().parse( flattendPom ) +assert 1 == flattendProject.dependencies.size() +assert 1 == flattendProject.dependencies.dependency.size() + + diff --git a/src/it/projects/flatten-dependency-all-optional/parent/pom.xml b/src/it/projects/flatten-dependency-all-optional/parent/pom.xml new file mode 100644 index 00000000..7f14a198 --- /dev/null +++ b/src/it/projects/flatten-dependency-all-optional/parent/pom.xml @@ -0,0 +1,20 @@ + + 4.0.0 + org.codehaus.mojo.flatten.its + parent + 1.1 + pom + + + + + + org.codehaus.mojo.flatten.its + dep + 1.1 + true + + + + diff --git a/src/it/projects/flatten-dependency-all-optional/pom.xml b/src/it/projects/flatten-dependency-all-optional/pom.xml new file mode 100644 index 00000000..c1fd7a7f --- /dev/null +++ b/src/it/projects/flatten-dependency-all-optional/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + org.codehaus.mojo.flatten.its + flatten-dependency-all-optional + 1.0.0 + pom + + + org.codehaus.mojo.flatten.its + parent + 1.1 + parent + + + + + verify + + + org.codehaus.mojo + flatten-maven-plugin + + all + + + + + \ No newline at end of file diff --git a/src/it/projects/flatten-dependency-all-optional/verify.groovy b/src/it/projects/flatten-dependency-all-optional/verify.groovy new file mode 100644 index 00000000..0de9b5b1 --- /dev/null +++ b/src/it/projects/flatten-dependency-all-optional/verify.groovy @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +File originalPom = new File( basedir, 'pom.xml' ) +assert originalPom.exists() diff --git a/src/it/projects/flatten-dependency-all-provided-children/pom.xml b/src/it/projects/flatten-dependency-all-provided-children/pom.xml new file mode 100644 index 00000000..152ad6e9 --- /dev/null +++ b/src/it/projects/flatten-dependency-all-provided-children/pom.xml @@ -0,0 +1,28 @@ + + 4.0.0 + org.codehaus.mojo.flatten.its + flatten-dependency-all-depmgnt-provided-transitive + 0.0.1-SNAPSHOT + + + + org.codehaus.mojo.flatten.its + parent-deps + 1 + provided + + + + + verify + + + org.codehaus.mojo + flatten-maven-plugin + + all + + + + + \ No newline at end of file diff --git a/src/it/projects/flatten-dependency-all-provided-children/verify.groovy b/src/it/projects/flatten-dependency-all-provided-children/verify.groovy new file mode 100644 index 00000000..3d175eba --- /dev/null +++ b/src/it/projects/flatten-dependency-all-provided-children/verify.groovy @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +File originalPom = new File( basedir, 'pom.xml' ) +assert originalPom.exists() + +def originalProject = new XmlSlurper().parse( originalPom ) +assert 1 == originalProject.dependencies.size() + +File flattendPom = new File( basedir, '.flattened-pom.xml' ) +assert flattendPom.exists() + +def flattendProject = new XmlSlurper().parse( flattendPom ) +assert 1 == flattendProject.dependencies.size() +assert 1 == flattendProject.dependencies.dependency.size() \ No newline at end of file diff --git a/src/it/projects/flatten-dependency-all-provided-direct/pom.xml b/src/it/projects/flatten-dependency-all-provided-direct/pom.xml new file mode 100644 index 00000000..246d3976 --- /dev/null +++ b/src/it/projects/flatten-dependency-all-provided-direct/pom.xml @@ -0,0 +1,28 @@ + + 4.0.0 + org.codehaus.mojo.flatten.its + flatten-dependency-all-provided-direct + 0.0.1-SNAPSHOT + + + + org.codehaus.mojo.flatten.its + dep + 1.1 + provided + + + + + verify + + + org.codehaus.mojo + flatten-maven-plugin + + all + + + + + \ No newline at end of file diff --git a/src/it/projects/flatten-dependency-all-provided-direct/verify.groovy b/src/it/projects/flatten-dependency-all-provided-direct/verify.groovy new file mode 100644 index 00000000..c6598462 --- /dev/null +++ b/src/it/projects/flatten-dependency-all-provided-direct/verify.groovy @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +File originalPom = new File( basedir, 'pom.xml' ) +assert originalPom.exists() + +def originalProject = new XmlSlurper().parse( originalPom ) +assert 1 == originalProject.dependencies.size() + +File flattendPom = new File( basedir, '.flattened-pom.xml' ) +assert flattendPom.exists() + +def flattenedProject = new XmlSlurper().parse( flattendPom ) +assert 1 == flattenedProject.dependencies.size() +assert 1 == flattenedProject.dependencies.dependency.size() + +String scope = flattenedProject.dependencies.dependency.scope +assert "provided" == scope \ No newline at end of file diff --git a/src/it/projects/flatten-dependency-all-provided-transitive/pom.xml b/src/it/projects/flatten-dependency-all-provided-transitive/pom.xml new file mode 100644 index 00000000..05fb4f2d --- /dev/null +++ b/src/it/projects/flatten-dependency-all-provided-transitive/pom.xml @@ -0,0 +1,27 @@ + + 4.0.0 + org.codehaus.mojo.flatten.its + flatten-dependency-all-provided-transitive + 0.0.1-SNAPSHOT + + + + org.codehaus.mojo.flatten.its + parent-deps + 1.1 + + + + + verify + + + org.codehaus.mojo + flatten-maven-plugin + + all + + + + + \ No newline at end of file diff --git a/src/it/projects/flatten-dependency-all-provided-transitive/verify.groovy b/src/it/projects/flatten-dependency-all-provided-transitive/verify.groovy new file mode 100644 index 00000000..4cd635c5 --- /dev/null +++ b/src/it/projects/flatten-dependency-all-provided-transitive/verify.groovy @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +File originalPom = new File( basedir, 'pom.xml' ) +assert originalPom.exists() + +def originalProject = new XmlSlurper().parse( originalPom ) +assert 1 == originalProject.dependencies.size() + +File flattendPom = new File( basedir, '.flattened-pom.xml' ) +assert flattendPom.exists() + +def flattenedProject = new XmlSlurper().parse( flattendPom ) +assert 1 == flattenedProject.dependencies.size() +assert 1 == flattenedProject.dependencies.dependency.size() \ No newline at end of file diff --git a/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java b/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java index e12a165e..c6a187da 100644 --- a/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java +++ b/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java @@ -200,7 +200,7 @@ @Mojo( name = "flatten", requiresProject = true, requiresDirectInvocation = false, executionStrategy = "once-per-session", requiresDependencyCollection = ResolutionScope.RUNTIME, threadSafe = true ) // CHECKSTYLE_ON: LineLength public class FlattenMojo - extends AbstractFlattenMojo + extends AbstractFlattenMojo { private static final int INITIAL_POM_WRITER_SIZE = 4096; @@ -341,7 +341,7 @@ public class FlattenMojo */ @Component( role = ModelInterpolator.class ) private ModelInterpolator modelInterpolator; - + /** * The {@link ModelInterpolator} used to resolve variables. */ @@ -378,7 +378,7 @@ public FlattenMojo() * {@inheritDoc} */ public void execute() - throws MojoExecutionException, MojoFailureException + throws MojoExecutionException, MojoFailureException { getLog().info( "Generating flattened POM of project " + this.project.getId() + "..." ); @@ -405,7 +405,7 @@ public void execute() * @throws MojoExecutionException if anything goes wrong. */ protected String extractHeaderComment( File xmlFile ) - throws MojoExecutionException + throws MojoExecutionException { try @@ -433,7 +433,7 @@ protected String extractHeaderComment( File xmlFile ) * @throws MojoExecutionException if the operation failed (e.g. due to an {@link IOException}). */ protected void writePom( Model pom, File pomFile, String headerComment ) - throws MojoExecutionException + throws MojoExecutionException { File parentFile = pomFile.getParentFile(); @@ -482,7 +482,7 @@ protected void writePom( Model pom, File pomFile, String headerComment ) * @throws MojoExecutionException if anything goes wrong. */ protected void writeStringToFile( String data, File file, String encoding ) - throws MojoExecutionException + throws MojoExecutionException { if (System.getProperty("os.name").contains("Windows")) { @@ -574,13 +574,13 @@ protected Model createFlattenedPom( File pomFile ) throws MojoExecutionException if ( property.isElement() ) { Model sourceModel = getSourceModel( descriptor, property, effectivePom, originalPom, resolvedPom, - interpolatedPom, cleanPom ); + interpolatedPom, cleanPom ); if ( sourceModel == null ) { if ( property.isRequired() ) { throw new MojoFailureException( "Property " + property.getName() - + " is required and can not be removed!" ); + + " is required and can not be removed!" ); } } else @@ -599,10 +599,10 @@ private Model createResolvedPom( ModelBuildingRequest buildingRequest ) Model originalModel = this.project.getOriginalModel().clone(); if (this.flattenMode == FlattenMode.resolveCiFriendliesOnly) { return this.modelCiFriendlyInterpolator.interpolateModel( originalModel, this.project.getModel().getProjectDirectory(), - buildingRequest, problems ); + buildingRequest, problems ); } return this.modelInterpolator.interpolateModel( originalModel, this.project.getModel().getProjectDirectory(), - buildingRequest, problems ); + buildingRequest, problems ); } /** @@ -712,7 +712,7 @@ private Model getSourceModel( FlattenDescriptor descriptor, PomProperty prope ElementHandling handling = descriptor.getHandling( property ); getLog().debug( "Property " + property.getName() + " will be handled using " + handling - + " in flattened POM." ); + + " in flattened POM." ); switch ( handling ) { case expand: @@ -758,7 +758,7 @@ protected static List createFlattenedRepositories( List } private FlattenDescriptor getFlattenDescriptor() - throws MojoFailureException + throws MojoFailureException { FlattenDescriptor descriptor = this.pomElements; if ( descriptor == null ) @@ -822,13 +822,13 @@ private ModelBuildingRequest createModelBuildingRequest( File pomFile ) { FlattenModelResolver resolver = new FlattenModelResolver( this.localRepository, this.artifactFactory, - this.dependencyResolver, this.session.getProjectBuildingRequest(), getReactorModelsFromSession() ); + this.dependencyResolver, this.session.getProjectBuildingRequest(), getReactorModelsFromSession() ); Properties userProperties = this.session.getUserProperties(); List activeProfiles = this.session.getRequest().getActiveProfiles(); // @formatter:off ModelBuildingRequest buildingRequest = - new DefaultModelBuildingRequest().setUserProperties( userProperties ).setSystemProperties( System.getProperties() ).setPomFile( pomFile ).setModelResolver( resolver ).setActiveProfileIds( activeProfiles ); + new DefaultModelBuildingRequest().setUserProperties( userProperties ).setSystemProperties( System.getProperties() ).setPomFile( pomFile ).setModelResolver( resolver ).setActiveProfileIds( activeProfiles ); // @formatter:on return buildingRequest; } @@ -858,8 +858,8 @@ private List getReactorModelsFromSession() * @throws MojoExecutionException if anything goes wrong. */ protected Model createEffectivePom( ModelBuildingRequest buildingRequest, - final boolean embedBuildProfileDependencies, final FlattenMode flattenMode ) - throws MojoExecutionException + final boolean embedBuildProfileDependencies, final FlattenMode flattenMode ) + throws MojoExecutionException { ModelBuildingResult buildingResult; try @@ -1035,11 +1035,11 @@ private void createFlattenedDependenciesDirect( List projectDependen * The collected dependencies are stored in order, so that the leaf dependencies are prioritized in front of direct dependencies. * In addition, every non-leaf dependencies will exclude its own direct dependency, since all transitive dependencies * will be collected. - * + * * Transitive dependencies are all going to be collected and become a direct dependency. Maven should already resolve * versions properly because now the transitive dependencies are closer to the artifact. However, when this artifact is * being consumed, Maven Enforcer Convergence rule will fail because there may be multiple versions for the same transitive dependency. - * + * * Typically, exclusion can be done by using the wildcard. However, a known Maven issue prevents convergence enforcer from * working properly w/ wildcard exclusions. Thus, this will exclude each dependencies explicitly rather than using the wildcard. * @@ -1063,6 +1063,11 @@ private void createFlattenedDependenciesAll( List projectDependencie if (node.getArtifact().getGroupId().equals(projectArtifact.getGroupId()) && node.getArtifact().getArtifactId().equals(projectArtifact.getArtifactId())) { return true; } + if ("provided".equals(node.getArtifact().getScope())) { + DependencyNode parent = node.getParent(); + if(!parent.getArtifact().getGroupId().equals(projectArtifact.getGroupId()) || !parent.getArtifact().getArtifactId().equals(projectArtifact.getArtifactId())) + return false; + } if (node.getState() != DependencyNode.INCLUDED) return true; dependencyNodeLinkedList.add(node); return true; @@ -1182,7 +1187,7 @@ public boolean isUpdatePomFile() * document. */ private class SaxHeaderCommentHandler - extends DefaultHandler2 + extends DefaultHandler2 { /** true if root tag has already been visited, false otherwise. */ @@ -1215,7 +1220,7 @@ public String getHeaderComment() */ @Override public void comment( char[] ch, int start, int length ) - throws SAXException + throws SAXException { if ( !this.rootTagSeen ) @@ -1236,11 +1241,11 @@ public void comment( char[] ch, int start, int length ) */ @Override public void startElement( String uri, String localName, String qName, Attributes atts ) - throws SAXException + throws SAXException { this.rootTagSeen = true; } } -} +} \ No newline at end of file From 428837924d21ce06f2f5c713190f89e7a40e3df1 Mon Sep 17 00:00:00 2001 From: Saleh Mostafa Date: Mon, 13 Jul 2020 15:33:29 -0400 Subject: [PATCH 2/5] Removed accidentally included 'optional' test. --- .../parent/pom.xml | 20 ------------- .../flatten-dependency-all-optional/pom.xml | 30 ------------------- .../verify.groovy | 20 ------------- 3 files changed, 70 deletions(-) delete mode 100644 src/it/projects/flatten-dependency-all-optional/parent/pom.xml delete mode 100644 src/it/projects/flatten-dependency-all-optional/pom.xml delete mode 100644 src/it/projects/flatten-dependency-all-optional/verify.groovy diff --git a/src/it/projects/flatten-dependency-all-optional/parent/pom.xml b/src/it/projects/flatten-dependency-all-optional/parent/pom.xml deleted file mode 100644 index 7f14a198..00000000 --- a/src/it/projects/flatten-dependency-all-optional/parent/pom.xml +++ /dev/null @@ -1,20 +0,0 @@ - - 4.0.0 - org.codehaus.mojo.flatten.its - parent - 1.1 - pom - - - - - - org.codehaus.mojo.flatten.its - dep - 1.1 - true - - - - diff --git a/src/it/projects/flatten-dependency-all-optional/pom.xml b/src/it/projects/flatten-dependency-all-optional/pom.xml deleted file mode 100644 index c1fd7a7f..00000000 --- a/src/it/projects/flatten-dependency-all-optional/pom.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - 4.0.0 - org.codehaus.mojo.flatten.its - flatten-dependency-all-optional - 1.0.0 - pom - - - org.codehaus.mojo.flatten.its - parent - 1.1 - parent - - - - - verify - - - org.codehaus.mojo - flatten-maven-plugin - - all - - - - - \ No newline at end of file diff --git a/src/it/projects/flatten-dependency-all-optional/verify.groovy b/src/it/projects/flatten-dependency-all-optional/verify.groovy deleted file mode 100644 index 0de9b5b1..00000000 --- a/src/it/projects/flatten-dependency-all-optional/verify.groovy +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -File originalPom = new File( basedir, 'pom.xml' ) -assert originalPom.exists() From 7372d8b94581afa4b407945009b2c27b967e9d10 Mon Sep 17 00:00:00 2001 From: Saleh Mostafa Date: Mon, 13 Jul 2020 15:37:20 -0400 Subject: [PATCH 3/5] Fixed weird spacing modifications from before --- src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java b/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java index c6a187da..b85e0cb6 100644 --- a/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java +++ b/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java @@ -295,7 +295,7 @@ public class FlattenMojo * * * resolveCiFriendliesOnly - * Only resolves variables revision, sha1 and changelist. Keeps everything else. + * Only resolves variables revision, sha1 and changelist. Keeps everything else. * See Maven CI Friendly for further details. * * From a278b409a5d82604bb93329cb6f9979a8e0a9486 Mon Sep 17 00:00:00 2001 From: Saleh Mostafa Date: Tue, 14 Jul 2020 12:33:50 -0400 Subject: [PATCH 4/5] Fixed weird spacing issues with PR --- .../codehaus/mojo/flatten/FlattenMojo.java | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java b/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java index b85e0cb6..2cf1ba0d 100644 --- a/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java +++ b/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java @@ -200,7 +200,7 @@ @Mojo( name = "flatten", requiresProject = true, requiresDirectInvocation = false, executionStrategy = "once-per-session", requiresDependencyCollection = ResolutionScope.RUNTIME, threadSafe = true ) // CHECKSTYLE_ON: LineLength public class FlattenMojo - extends AbstractFlattenMojo + extends AbstractFlattenMojo { private static final int INITIAL_POM_WRITER_SIZE = 4096; @@ -295,7 +295,7 @@ public class FlattenMojo * * * resolveCiFriendliesOnly - * Only resolves variables revision, sha1 and changelist. Keeps everything else. + * Only resolves variables revision, sha1 and changelist. Keeps everything else. * See Maven CI Friendly for further details. * * @@ -341,7 +341,7 @@ public class FlattenMojo */ @Component( role = ModelInterpolator.class ) private ModelInterpolator modelInterpolator; - + /** * The {@link ModelInterpolator} used to resolve variables. */ @@ -378,7 +378,7 @@ public FlattenMojo() * {@inheritDoc} */ public void execute() - throws MojoExecutionException, MojoFailureException + throws MojoExecutionException, MojoFailureException { getLog().info( "Generating flattened POM of project " + this.project.getId() + "..." ); @@ -405,7 +405,7 @@ public void execute() * @throws MojoExecutionException if anything goes wrong. */ protected String extractHeaderComment( File xmlFile ) - throws MojoExecutionException + throws MojoExecutionException { try @@ -433,7 +433,7 @@ protected String extractHeaderComment( File xmlFile ) * @throws MojoExecutionException if the operation failed (e.g. due to an {@link IOException}). */ protected void writePom( Model pom, File pomFile, String headerComment ) - throws MojoExecutionException + throws MojoExecutionException { File parentFile = pomFile.getParentFile(); @@ -482,7 +482,7 @@ protected void writePom( Model pom, File pomFile, String headerComment ) * @throws MojoExecutionException if anything goes wrong. */ protected void writeStringToFile( String data, File file, String encoding ) - throws MojoExecutionException + throws MojoExecutionException { if (System.getProperty("os.name").contains("Windows")) { @@ -574,13 +574,13 @@ protected Model createFlattenedPom( File pomFile ) throws MojoExecutionException if ( property.isElement() ) { Model sourceModel = getSourceModel( descriptor, property, effectivePom, originalPom, resolvedPom, - interpolatedPom, cleanPom ); + interpolatedPom, cleanPom ); if ( sourceModel == null ) { if ( property.isRequired() ) { throw new MojoFailureException( "Property " + property.getName() - + " is required and can not be removed!" ); + + " is required and can not be removed!" ); } } else @@ -599,10 +599,10 @@ private Model createResolvedPom( ModelBuildingRequest buildingRequest ) Model originalModel = this.project.getOriginalModel().clone(); if (this.flattenMode == FlattenMode.resolveCiFriendliesOnly) { return this.modelCiFriendlyInterpolator.interpolateModel( originalModel, this.project.getModel().getProjectDirectory(), - buildingRequest, problems ); + buildingRequest, problems ); } return this.modelInterpolator.interpolateModel( originalModel, this.project.getModel().getProjectDirectory(), - buildingRequest, problems ); + buildingRequest, problems ); } /** @@ -712,7 +712,7 @@ private Model getSourceModel( FlattenDescriptor descriptor, PomProperty prope ElementHandling handling = descriptor.getHandling( property ); getLog().debug( "Property " + property.getName() + " will be handled using " + handling - + " in flattened POM." ); + + " in flattened POM." ); switch ( handling ) { case expand: @@ -758,7 +758,7 @@ protected static List createFlattenedRepositories( List } private FlattenDescriptor getFlattenDescriptor() - throws MojoFailureException + throws MojoFailureException { FlattenDescriptor descriptor = this.pomElements; if ( descriptor == null ) @@ -822,13 +822,13 @@ private ModelBuildingRequest createModelBuildingRequest( File pomFile ) { FlattenModelResolver resolver = new FlattenModelResolver( this.localRepository, this.artifactFactory, - this.dependencyResolver, this.session.getProjectBuildingRequest(), getReactorModelsFromSession() ); + this.dependencyResolver, this.session.getProjectBuildingRequest(), getReactorModelsFromSession() ); Properties userProperties = this.session.getUserProperties(); List activeProfiles = this.session.getRequest().getActiveProfiles(); // @formatter:off ModelBuildingRequest buildingRequest = - new DefaultModelBuildingRequest().setUserProperties( userProperties ).setSystemProperties( System.getProperties() ).setPomFile( pomFile ).setModelResolver( resolver ).setActiveProfileIds( activeProfiles ); + new DefaultModelBuildingRequest().setUserProperties( userProperties ).setSystemProperties( System.getProperties() ).setPomFile( pomFile ).setModelResolver( resolver ).setActiveProfileIds( activeProfiles ); // @formatter:on return buildingRequest; } @@ -858,8 +858,8 @@ private List getReactorModelsFromSession() * @throws MojoExecutionException if anything goes wrong. */ protected Model createEffectivePom( ModelBuildingRequest buildingRequest, - final boolean embedBuildProfileDependencies, final FlattenMode flattenMode ) - throws MojoExecutionException + final boolean embedBuildProfileDependencies, final FlattenMode flattenMode ) + throws MojoExecutionException { ModelBuildingResult buildingResult; try @@ -1035,11 +1035,11 @@ private void createFlattenedDependenciesDirect( List projectDependen * The collected dependencies are stored in order, so that the leaf dependencies are prioritized in front of direct dependencies. * In addition, every non-leaf dependencies will exclude its own direct dependency, since all transitive dependencies * will be collected. - * + * * Transitive dependencies are all going to be collected and become a direct dependency. Maven should already resolve * versions properly because now the transitive dependencies are closer to the artifact. However, when this artifact is * being consumed, Maven Enforcer Convergence rule will fail because there may be multiple versions for the same transitive dependency. - * + * * Typically, exclusion can be done by using the wildcard. However, a known Maven issue prevents convergence enforcer from * working properly w/ wildcard exclusions. Thus, this will exclude each dependencies explicitly rather than using the wildcard. * @@ -1187,7 +1187,7 @@ public boolean isUpdatePomFile() * document. */ private class SaxHeaderCommentHandler - extends DefaultHandler2 + extends DefaultHandler2 { /** true if root tag has already been visited, false otherwise. */ @@ -1220,7 +1220,7 @@ public String getHeaderComment() */ @Override public void comment( char[] ch, int start, int length ) - throws SAXException + throws SAXException { if ( !this.rootTagSeen ) @@ -1241,11 +1241,11 @@ public void comment( char[] ch, int start, int length ) */ @Override public void startElement( String uri, String localName, String qName, Attributes atts ) - throws SAXException + throws SAXException { this.rootTagSeen = true; } } -} \ No newline at end of file +} From d6c1c00553dafaa28bbeeeef3160e6b885737661 Mon Sep 17 00:00:00 2001 From: Saleh Mostafa Date: Wed, 29 Jul 2020 01:32:51 -0400 Subject: [PATCH 5/5] Fixing spacing issue --- .../java/org/codehaus/mojo/flatten/FlattenMojo.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java b/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java index f02b399d..eaadbd73 100644 --- a/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java +++ b/src/main/java/org/codehaus/mojo/flatten/FlattenMojo.java @@ -1067,16 +1067,20 @@ private void createFlattenedDependenciesAll( List projectDependencie { return true; } - - if ("provided".equals(node.getArtifact().getScope())) { + if ("provided".equals(node.getArtifact().getScope())) + { DependencyNode parent = node.getParent(); if(!parent.getArtifact().getGroupId().equals(projectArtifact.getGroupId()) || !parent.getArtifact().getArtifactId().equals(projectArtifact.getArtifactId())) + { return false; + } } - if (node.getState() != DependencyNode.INCLUDED) { + if (node.getState() != DependencyNode.INCLUDED) + { return false; } - if (node.getArtifact().isOptional()) { + if (node.getArtifact().isOptional()) + { return false; } dependencyNodeLinkedList.add(node);