-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #74: Add display-extension-updates
- Loading branch information
1 parent
426fac7
commit 6d554df
Showing
30 changed files
with
1,316 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
versions-common/src/main/java/org/codehaus/mojo/versions/utils/CoreExtensionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.codehaus.mojo.versions.utils; | ||
|
||
/* | ||
* Copyright MojoHaus and Contributors | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.stream.Stream; | ||
|
||
import org.apache.maven.model.Extension; | ||
import org.apache.maven.project.MavenProject; | ||
import org.codehaus.mojo.versions.model.io.xpp3.CoreExtensionsXpp3Reader; | ||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; | ||
|
||
/** | ||
* Utilities for reading and handling core extensions. | ||
* | ||
* @author Andrzej Jarmoniuk | ||
* @since 2.15.0 | ||
*/ | ||
public final class CoreExtensionUtils { | ||
/** | ||
* Reads the core extensions (not build extensions) configured for the given project | ||
* from the {@code ${project}/.mvn/extensions.xml} file. | ||
* | ||
* @param project {@link MavenProject} instance | ||
* @return stream of core extensions defined in the {@code ${project}/.mvn/extensions.xml} file | ||
* @throws IOException thrown if a file I/O operation fails | ||
* @throws XmlPullParserException thrown if the file cannot be parsed | ||
* @since 2.15.0 | ||
*/ | ||
public static Stream<Extension> getCoreExtensions(MavenProject project) throws IOException, XmlPullParserException { | ||
Path extensionsFile = project.getBasedir().toPath().resolve(".mvn/extensions.xml"); | ||
if (!Files.isRegularFile(extensionsFile)) { | ||
return Stream.empty(); | ||
} | ||
|
||
try (Reader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(extensionsFile)))) { | ||
return new CoreExtensionsXpp3Reader() | ||
.read(reader).getExtensions().stream().map(ex -> ExtensionBuilder.newBuilder() | ||
.withGroupId(ex.getGroupId()) | ||
.withArtifactId(ex.getArtifactId()) | ||
.withVersion(ex.getVersion()) | ||
.build()); | ||
} | ||
} | ||
} |
Oops, something went wrong.