Skip to content

Commit 4bd22cd

Browse files
committed
Simplify build and consumer pom transformation
1 parent 584b342 commit 4bd22cd

File tree

59 files changed

+703
-3799
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+703
-3799
lines changed

maven-bom/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,6 @@ under the License.
132132
<artifactId>maven-model-builder</artifactId>
133133
<version>${project.version}</version>
134134
</dependency>
135-
<dependency>
136-
<groupId>org.apache.maven</groupId>
137-
<artifactId>maven-model-transform</artifactId>
138-
<version>${project.version}</version>
139-
</dependency>
140135
<dependency>
141136
<groupId>org.apache.maven</groupId>
142137
<artifactId>maven-plugin-api</artifactId>

maven-core/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ under the License.
7171
<groupId>org.apache.maven</groupId>
7272
<artifactId>maven-model-builder</artifactId>
7373
</dependency>
74-
<dependency>
75-
<groupId>org.apache.maven</groupId>
76-
<artifactId>maven-model-transform</artifactId>
77-
</dependency>
7874
<dependency>
7975
<groupId>org.apache.maven</groupId>
8076
<artifactId>maven-resolver-provider</artifactId>

maven-core/src/main/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformer.java

Lines changed: 136 additions & 183 deletions
Large diffs are not rendered by default.

maven-core/src/main/java/org/apache/maven/xml/internal/DefaultConsumerPomXMLFilterFactory.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

maven-core/src/test/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformerTest.java

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323
import java.nio.file.Files;
2424
import java.nio.file.Path;
2525
import java.nio.file.Paths;
26-
import java.util.Collections;
2726

2827
import org.apache.maven.model.Model;
28+
import org.apache.maven.model.building.DefaultModelBuilderFactory;
29+
import org.apache.maven.model.building.ModelBuilder;
2930
import org.apache.maven.model.building.TransformerContext;
3031
import org.apache.maven.model.v4.MavenStaxReader;
3132
import org.apache.maven.project.MavenProject;
@@ -40,32 +41,28 @@
4041
import static org.mockito.Mockito.when;
4142

4243
class ConsumerPomArtifactTransformerTest {
44+
45+
ModelBuilder modelBuilder = new DefaultModelBuilderFactory().newInstance();
46+
4347
@Test
44-
void buildTransform() throws Exception {
48+
void transform() throws Exception {
49+
RepositorySystemSession systemSessionMock = Mockito.mock(RepositorySystemSession.class);
50+
SessionData sessionDataMock = Mockito.mock(SessionData.class);
51+
when(systemSessionMock.getData()).thenReturn(sessionDataMock);
52+
when(sessionDataMock.get(any())).thenReturn(new NoTransformerContext());
53+
4554
Path beforePomFile =
4655
Paths.get("src/test/resources/projects/transform/before.pom").toAbsolutePath();
4756
Path afterPomFile =
4857
Paths.get("src/test/resources/projects/transform/after.pom").toAbsolutePath();
49-
Path temp = Files.createTempFile("consumer-", ".pom");
50-
51-
try (InputStream expected = Files.newInputStream(afterPomFile);
52-
InputStream result = ConsumerPomArtifactTransformer.BuildPomArtifact.transform(
53-
beforePomFile, new NoTransformerContext(), Collections.emptyMap())) {
54-
XmlAssert.assertThat(result).and(expected).areIdentical();
55-
}
56-
}
57-
58-
@Test
59-
void consumerTransform() throws Exception {
60-
Path beforePomFile = Paths.get("src/test/resources/projects/transform/consumer-before.pom")
61-
.toAbsolutePath();
62-
Path afterPomFile = Paths.get("src/test/resources/projects/transform/consumer-after.pom")
63-
.toAbsolutePath();
6458
Path tempFile = Files.createTempFile("", ".pom");
6559
Files.delete(tempFile);
6660
try (InputStream expected = Files.newInputStream(beforePomFile)) {
6761
Model model = new Model(new MavenStaxReader().read(expected));
68-
ConsumerPomArtifactTransformer.ConsumerPomArtifact.transform(model.getDelegate(), tempFile);
62+
MavenProject project = new MavenProject(model);
63+
ConsumerPomArtifactTransformer t = new ConsumerPomArtifactTransformer(modelBuilder);
64+
t.createConsumerPomArtifact(project, tempFile, systemSessionMock)
65+
.transform(beforePomFile, tempFile, model.getDelegate());
6966
}
7067
XmlAssert.assertThat(afterPomFile.toFile()).and(tempFile.toFile()).areIdentical();
7168
}
@@ -79,8 +76,7 @@ void injectTransformedArtifactsWithoutPomShouldNotInjectAnyArtifacts() throws IO
7976
when(systemSessionMock.getData()).thenReturn(sessionDataMock);
8077
when(sessionDataMock.get(any())).thenReturn(new NoTransformerContext());
8178

82-
new ConsumerPomArtifactTransformer(Collections.emptyMap())
83-
.injectTransformedArtifacts(emptyProject, systemSessionMock);
79+
new ConsumerPomArtifactTransformer(modelBuilder).injectTransformedArtifacts(emptyProject, systemSessionMock);
8480

8581
assertThat(emptyProject.getAttachedArtifacts()).isEmpty();
8682
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.model;
20+
21+
import javax.inject.Inject;
22+
23+
import java.io.File;
24+
import java.util.Collections;
25+
import java.util.List;
26+
27+
import org.apache.maven.bridge.MavenRepositorySystem;
28+
import org.apache.maven.execution.DefaultMavenExecutionRequest;
29+
import org.apache.maven.execution.MavenExecutionRequest;
30+
import org.apache.maven.internal.aether.DefaultRepositorySystemSessionFactory;
31+
import org.apache.maven.project.DefaultProjectBuildingRequest;
32+
import org.apache.maven.project.ProjectBuilder;
33+
import org.apache.maven.project.ProjectBuildingResult;
34+
import org.codehaus.plexus.testing.PlexusTest;
35+
import org.junit.jupiter.api.Test;
36+
37+
@PlexusTest
38+
public class ModelBuilderTest {
39+
40+
@Inject
41+
ProjectBuilder projectBuilder;
42+
43+
@Inject
44+
MavenRepositorySystem repositorySystem;
45+
46+
@Inject
47+
DefaultRepositorySystemSessionFactory repositorySessionFactory;
48+
49+
@Test
50+
void testModelBuilder() throws Exception {
51+
MavenExecutionRequest mavenRequest = new DefaultMavenExecutionRequest();
52+
mavenRequest.setLocalRepository(repositorySystem.createLocalRepository(new File("target/test-repo/")));
53+
54+
DefaultProjectBuildingRequest request = new DefaultProjectBuildingRequest();
55+
request.setRepositorySession(repositorySessionFactory.newRepositorySession(mavenRequest));
56+
List<ProjectBuildingResult> results = projectBuilder.build(
57+
Collections.singletonList(new File("src/test/resources/projects/tree/pom.xml")), true, request);
58+
}
59+
}

maven-core/src/test/java/org/apache/maven/project/ProjectBuilderTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ void testReadInvalidPom() throws Exception {
227227
File pomFile = new File("src/test/resources/projects/badPom.xml").getAbsoluteFile();
228228
MavenSession mavenSession = createMavenSession(null);
229229
ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest();
230-
configuration.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
230+
configuration.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_STRICT);
231231
configuration.setRepositorySession(mavenSession.getRepositorySession());
232232
org.apache.maven.project.ProjectBuilder projectBuilder =
233233
getContainer().lookup(org.apache.maven.project.ProjectBuilder.class);
@@ -245,7 +245,8 @@ void testReadInvalidPom() throws Exception {
245245
assertThat(pex.getResults().get(0).getProblems().size(), greaterThan(0));
246246
assertThat(
247247
pex.getResults(),
248-
contains(projectBuildingResultWithProblemMessage("expected START_TAG or END_TAG not CHARACTERS")));
248+
contains(projectBuildingResultWithProblemMessage(
249+
"Received non-all-whitespace CHARACTERS or CDATA event in nextTag()")));
249250
}
250251

251252
@Test
Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,25 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<!--
4-
Licensed to the Apache Software Foundation (ASF) under one
5-
or more contributor license agreements. See the NOTICE file
6-
distributed with this work for additional information
7-
regarding copyright ownership. The ASF licenses this file
8-
to you under the Apache License, Version 2.0 (the
9-
"License"); you may not use this file except in compliance
10-
with the License. You may obtain a copy of the License at
11-
12-
http://www.apache.org/licenses/LICENSE-2.0
13-
14-
Unless required by applicable law or agreed to in writing,
15-
software distributed under the License is distributed on an
16-
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17-
KIND, either express or implied. See the License for the
18-
specific language governing permissions and limitations
19-
under the License.
20-
-->
21-
22-
<project xmlns="http://maven.apache.org/POM/4.0.0"
23-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
253
<modelVersion>4.0.0</modelVersion>
26-
274
<groupId>test</groupId>
285
<artifactId>test</artifactId>
296
<version>0.1-SNAPSHOT</version>
307
<packaging>pom</packaging>
31-
32-
33-
348
<build>
359
<pluginManagement>
3610
<plugins>
3711
<plugin>
38-
<groupId>org.apache.maven.plugins</groupId>
3912
<artifactId>maven-compiler-plugin</artifactId>
4013
<version>2.1</version>
4114
<configuration>
42-
<source> 1.5 </source>
15+
<source>1.5</source>
4316
<target xml:space="preserve"> 1.5 </target>
4417
</configuration>
4518
</plugin>
4619
</plugins>
4720
</pluginManagement>
4821
<plugins>
4922
<plugin>
50-
<groupId>org.apache.maven.plugins</groupId>
5123
<artifactId>maven-compiler-plugin</artifactId>
5224
<executions>
5325
<execution>
@@ -57,10 +29,9 @@ under the License.
5729
</plugin>
5830
</plugins>
5931
</build>
60-
6132
<profiles>
6233
<profile>
63-
<id>default</id>
34+
<id>default-active</id>
6435
<activation>
6536
<activeByDefault>true</activeByDefault>
6637
</activation>
@@ -80,4 +51,4 @@ under the License.
8051
</properties>
8152
</profile>
8253
</profiles>
83-
</project>
54+
</project>

maven-core/src/test/resources/projects/transform/before.pom

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ specific language governing permissions and limitations
1919
under the License.
2020
-->
2121

22-
<project xmlns="http://maven.apache.org/POM/4.0.0"
22+
<project xmlns="http://maven.apache.org/POM/4.1.0"
2323
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
25-
<modelVersion>4.0.0</modelVersion>
24+
xsi:schemaLocation="http://maven.apache.org/POM/4.1.0 https://maven.apache.org/xsd/maven-4.1.0.xsd"
25+
root="true">
26+
<modelVersion>4.1.0</modelVersion>
2627

2728
<groupId>test</groupId>
2829
<artifactId>test</artifactId>
@@ -63,7 +64,7 @@ under the License.
6364

6465
<profiles>
6566
<profile>
66-
<id>default</id>
67+
<id>default-active</id>
6768
<activation>
6869
<activeByDefault>true</activeByDefault>
6970
</activation>

maven-core/src/test/resources/projects/transform/consumer-after.pom

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)