Skip to content

Commit

Permalink
Issue mojohaus#74: Add display-extension-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejj0 committed Feb 13, 2023
1 parent c88c7b2 commit f0b85a5
Show file tree
Hide file tree
Showing 17 changed files with 409 additions and 99 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
<module>versions-maven-plugin</module>
<module>versions-model-report</module>
<module>versions-model</module>
<module>versions-model-core-extensions</module>
<module>versions-test</module>
</modules>

Expand Down
5 changes: 5 additions & 0 deletions versions-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<artifactId>versions-model</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.mojo.versions</groupId>
<artifactId>versions-model-core-extensions</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.maven</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package org.codehaus.mojo.versions.api;

/*
* 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
* 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
* 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.
* 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.BufferedInputStream;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package org.codehaus.mojo.versions.api;

/*
* 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
* 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
* 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.
* 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.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package org.codehaus.mojo.versions.filtering;

/*
* 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
* 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
* 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.
* 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.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import java.util.stream.Stream;

import org.apache.maven.cli.internal.extension.model.io.xpp3.CoreExtensionsXpp3Reader;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Extension;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;

/**
Expand All @@ -40,14 +40,14 @@ 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 session {@link MavenSession} instance
* @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(MavenSession session) throws IOException, XmlPullParserException {
Path extensionsFile = session.getCurrentProject().getBasedir().toPath().resolve(".mvn/extensions.xml");
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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
package org.codehaus.mojo.versions.utils;

/*
* 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
* 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
* 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.
* 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.
*/

package org.codehaus.mojo.versions.utils;

import java.util.Optional;

import org.apache.maven.model.Dependency;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void testNoExtensions() throws XmlPullParserException, IOException {
new File("src/test/resources/org/codehaus/mojo/versions/utils/core-extensions/no-extensions"));
MavenSession session = mock(MavenSession.class);
when(session.getCurrentProject()).thenReturn(project);
assertThat(CoreExtensionUtils.getCoreExtensions(session).findAny(), is(Optional.empty()));
assertThat(CoreExtensionUtils.getCoreExtensions(project).findAny(), is(Optional.empty()));
}

@Test
Expand All @@ -59,7 +59,7 @@ public void testExtensionsFound() throws XmlPullParserException, IOException {
MavenSession session = mock(MavenSession.class);
when(session.getCurrentProject()).thenReturn(project);
Set<Extension> extensions =
CoreExtensionUtils.getCoreExtensions(session).collect(Collectors.toSet());
CoreExtensionUtils.getCoreExtensions(project).collect(Collectors.toSet());
assertThat(
extensions,
hasItems(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">
<extension>
<groupId>localhost</groupId>
<artifactId>dummy-impl</artifactId>
<version>1.0</version>
</extension>
</extensions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>localhost</groupId>
<artifactId>it-display-extension-updates-004</artifactId>
<version>1.0</version>
</parent>

<artifactId>child</artifactId>
<version>1.0</version>

<packaging>pom</packaging>

<build>
<extensions>
<extension>
<groupId>localhost</groupId>
<artifactId>dummy-maven-plugin</artifactId>
<version>${dummyMavenPluginVersion}</version>
</extension>
</extensions>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
invoker.goals.1 = ${project.groupId}:${project.artifactId}:${project.version}:display-extension-updates
invoker.mavenOpts.1 = -Dversions.outputFile=./output1.txt -DoutputEncoding=UTF-8

invoker.goals.2 = ${project.groupId}:${project.artifactId}:${project.version}:display-extension-updates
invoker.mavenOpts.2 = -DinterpolateProperties=false -Dversions.outputFile=./output2.txt -DoutputEncoding=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>localhost</groupId>
<artifactId>it-display-extension-updates-004</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<modules>
<module>child</module>
</modules>

<properties>
<dummyApiVersion>1.0</dummyApiVersion>
<dummyMavenPluginVersion>1.0</dummyMavenPluginVersion>
</properties>

<build>
<extensions>
<extension>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>${dummyApiVersion}</version>
</extension>
</extensions>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def parentOutput = new File( basedir, "output1.txt").text
assert parentOutput =~ /\Qlocalhost:dummy-maven-plugin\E\s*\.*\s*\Q1.0\E\s+->\s+\Q3.1\E/
assert parentOutput =~ /\Qlocalhost:dummy-api\E\s*\.*\s*\Q1.0\E\s+->\s+\Q3.0\E/

def childOutput = new File( basedir, "child/output1.txt")
assert !childOutput.exists()

def parentOutput2 = new File( basedir, "output2.txt").text
assert parentOutput2 =~ /\Qlocalhost:dummy-maven-plugin\E\s*\.*\s*\Q\u0024{dummyMavenPluginVersion}\E\s+->\s+\Q3.1\E/
assert parentOutput2 =~ /\Qlocalhost:dummy-api\E\s*\.*\s*\Q\u0024{dummyApiVersion}\E\s+->\s+\Q3.0\E/
Loading

0 comments on commit f0b85a5

Please sign in to comment.