Skip to content

Commit 7dfc53d

Browse files
committed
Simplify to avoid a new subproject
1 parent 7399ddb commit 7dfc53d

File tree

9 files changed

+202
-145
lines changed

9 files changed

+202
-145
lines changed

apache-maven/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ under the License.
4949
<groupId>org.apache.maven</groupId>
5050
<artifactId>maven-compat</artifactId>
5151
</dependency>
52-
<dependency>
53-
<groupId>org.apache.maven</groupId>
54-
<artifactId>maven-ci-friendly-versions</artifactId>
55-
</dependency>
5652

5753
<dependency>
5854
<groupId>commons-cli</groupId>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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.internal.impl;
20+
21+
import java.util.Arrays;
22+
23+
import org.apache.maven.api.Session;
24+
import org.apache.maven.api.di.Inject;
25+
import org.apache.maven.api.di.Named;
26+
import org.apache.maven.api.di.SessionScoped;
27+
import org.apache.maven.api.di.Singleton;
28+
import org.apache.maven.api.di.Typed;
29+
import org.apache.maven.api.model.Model;
30+
import org.apache.maven.api.model.Parent;
31+
import org.apache.maven.api.services.Lookup;
32+
import org.apache.maven.api.services.ModelTransformerException;
33+
import org.apache.maven.api.spi.ModelTransformer;
34+
35+
@Named("CIFriendlyVersion")
36+
@Singleton
37+
public class CIFriendlyVersionModelTransformer implements ModelTransformer {
38+
39+
public static final String SHA1_PROPERTY = "sha1";
40+
41+
public static final String CHANGELIST_PROPERTY = "changelist";
42+
43+
public static final String REVISION_PROPERTY = "revision";
44+
45+
private static final String INNER_COMPONENT_NAME = "CIFriendlyVersion$Inner";
46+
47+
private final Lookup lookup;
48+
49+
@Inject
50+
public CIFriendlyVersionModelTransformer(Lookup lookup) {
51+
this.lookup = lookup;
52+
}
53+
54+
@Override
55+
public Model transformFileModel(Model model) throws ModelTransformerException {
56+
return lookup.lookup(CIFriendlyVersionInner.class).transformFileModel(model);
57+
}
58+
59+
public interface CIFriendlyVersionInner {
60+
Model transformFileModel(Model model) throws ModelTransformerException;
61+
}
62+
63+
@SessionScoped
64+
@Named
65+
@Typed
66+
public static class CIFriendlyVersionInnerImpl implements CIFriendlyVersionInner {
67+
68+
private final Session session;
69+
70+
@Inject
71+
public CIFriendlyVersionInnerImpl(Session session) {
72+
this.session = session;
73+
}
74+
75+
@Override
76+
public Model transformFileModel(Model model) throws ModelTransformerException {
77+
return model.with()
78+
.version(replaceCiFriendlyVersion(model.getVersion()))
79+
.parent(replaceParent(model.getParent()))
80+
.build();
81+
}
82+
83+
private Parent replaceParent(Parent parent) {
84+
return parent != null ? parent.withVersion(replaceCiFriendlyVersion(parent.getVersion())) : null;
85+
}
86+
87+
protected String replaceCiFriendlyVersion(String version) {
88+
if (version != null) {
89+
for (String key : Arrays.asList(SHA1_PROPERTY, CHANGELIST_PROPERTY, REVISION_PROPERTY)) {
90+
String val = session.getUserProperties().get(key);
91+
if (val != null) {
92+
version = version.replace("${" + key + "}", val);
93+
}
94+
}
95+
}
96+
return version;
97+
}
98+
}
99+
}

maven-api-impl/src/test/java/org/apache/maven/internal/impl/standalone/TestApiStandalone.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@
2525
import org.apache.maven.api.DownloadedArtifact;
2626
import org.apache.maven.api.Node;
2727
import org.apache.maven.api.Session;
28+
import org.apache.maven.api.di.Named;
29+
import org.apache.maven.api.di.Priority;
30+
import org.apache.maven.api.di.Typed;
31+
import org.apache.maven.api.model.Model;
2832
import org.apache.maven.api.services.ModelBuilder;
2933
import org.apache.maven.api.services.ModelBuilderRequest;
3034
import org.apache.maven.api.services.ModelBuilderResult;
3135
import org.apache.maven.api.services.ModelSource;
36+
import org.apache.maven.api.services.ModelTransformerException;
37+
import org.apache.maven.internal.impl.CIFriendlyVersionModelTransformer;
3238
import org.junit.jupiter.api.Test;
3339

3440
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -60,4 +66,18 @@ void testStandalone() {
6066
assertNotNull(node);
6167
assertEquals(8, node.getChildren().size());
6268
}
69+
70+
/**
71+
* Disables the CIFriendlyVersionModelTransformer as it requires a session scope
72+
* which is not available in this test.
73+
*/
74+
@Named
75+
@Typed
76+
@Priority(100)
77+
public static class CIFriendlyVersionInnerImpl implements CIFriendlyVersionModelTransformer.CIFriendlyVersionInner {
78+
@Override
79+
public Model transformFileModel(Model model) throws ModelTransformerException {
80+
return model;
81+
}
82+
}
6383
}

maven-ci-friendly-versions/pom.xml

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

maven-ci-friendly-versions/src/main/java/org/apache/maven/internal/impl/model/CIFriendlyVersionModelTransformer.java

Lines changed: 0 additions & 74 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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;
20+
21+
import javax.inject.Named;
22+
23+
import org.apache.maven.api.model.Model;
24+
import org.apache.maven.api.services.ModelTransformerException;
25+
import org.apache.maven.internal.impl.CIFriendlyVersionModelTransformer;
26+
import org.eclipse.sisu.Priority;
27+
import org.eclipse.sisu.Typed;
28+
29+
/**
30+
* Disables the CIFriendlyVersionModelTransformer as it requires a session scope
31+
* which is not available in this test.
32+
*/
33+
@Named
34+
@Typed
35+
@Priority(100)
36+
public class CIFriendlyVersionInnerImpl implements CIFriendlyVersionModelTransformer.CIFriendlyVersionInner {
37+
@Override
38+
public Model transformFileModel(Model model) throws ModelTransformerException {
39+
return model;
40+
}
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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;
20+
21+
import javax.inject.Named;
22+
23+
import org.apache.maven.api.model.Model;
24+
import org.apache.maven.api.services.ModelTransformerException;
25+
import org.apache.maven.internal.impl.CIFriendlyVersionModelTransformer;
26+
import org.eclipse.sisu.Priority;
27+
import org.eclipse.sisu.Typed;
28+
29+
/**
30+
* Disables the CIFriendlyVersionModelTransformer as it requires a session scope
31+
* which is not available in this test.
32+
*/
33+
@Named
34+
@Typed
35+
@Priority(100)
36+
public class CIFriendlyVersionInnerImpl implements CIFriendlyVersionModelTransformer.CIFriendlyVersionInner {
37+
@Override
38+
public Model transformFileModel(Model model) throws ModelTransformerException {
39+
return model;
40+
}
41+
}

maven-embedder/src/main/java/org/apache/maven/cli/internal/BootstrapCoreExtensionManager.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import org.apache.maven.plugin.internal.DefaultPluginDependenciesResolver;
5959
import org.apache.maven.resolver.MavenChainedWorkspaceReader;
6060
import org.apache.maven.resolver.RepositorySystemSessionFactory;
61-
import org.apache.maven.session.scope.internal.SessionScope;
6261
import org.codehaus.plexus.DefaultPlexusContainer;
6362
import org.codehaus.plexus.PlexusContainer;
6463
import org.codehaus.plexus.classworlds.ClassWorld;
@@ -102,8 +101,6 @@ public class BootstrapCoreExtensionManager {
102101

103102
private final CoreExports coreExports;
104103

105-
private final PlexusContainer container;
106-
107104
private final ClassWorld classWorld;
108105

109106
private final ClassRealm parentRealm;
@@ -123,7 +120,6 @@ public BootstrapCoreExtensionManager(
123120
this.pluginDependenciesResolver = pluginDependenciesResolver;
124121
this.repositorySystemSessionFactory = repositorySystemSessionFactory;
125122
this.coreExports = coreExports;
126-
this.container = container;
127123
this.classWorld = ((DefaultPlexusContainer) container).getClassWorld();
128124
this.parentRealm = container.getContainerRealm();
129125
this.ideWorkspaceReader = ideWorkspaceReader;
@@ -141,19 +137,10 @@ public List<CoreExtensionEntry> loadCoreExtensions(
141137
InternalSession iSession = new SimpleSession(mSession, repoSystem, null);
142138
InternalSession.associate(repoSession, iSession);
143139

144-
SessionScope scope = container.lookup(SessionScope.class);
145-
scope.enter();
146-
scope.seed(Session.class, iSession);
147-
148140
List<RemoteRepository> repositories = RepositoryUtils.toRepos(request.getPluginArtifactRepositories());
149141
Interpolator interpolator = createInterpolator(request);
150142

151-
List<CoreExtensionEntry> entries =
152-
resolveCoreExtensions(repoSession, repositories, providedArtifacts, extensions, interpolator);
153-
154-
scope.exit();
155-
156-
return entries;
143+
return resolveCoreExtensions(repoSession, repositories, providedArtifacts, extensions, interpolator);
157144
}
158145
}
159146

0 commit comments

Comments
 (0)