Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.
*/
package org.apache.maven.it;

import java.io.File;
import java.util.Properties;

import org.apache.maven.shared.verifier.Verifier;
import org.apache.maven.shared.verifier.util.ResourceExtractor;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

class MavenITOutputCapabilitiesTest extends AbstractMavenIntegrationTestCase {
MavenITOutputCapabilitiesTest() {
super("[3.10.0-SNAPSHOT,)");
}

@Test
void injectsCapabilitiesIntoLegacyPluginsInParallelReactor() throws Exception {
File directory = ResourceExtractor.simpleExtractResources(getClass(), "/output-capabilities");
Verifier plugin = newVerifier(new File(directory, "plugin").getPath(), "remote");
plugin.addCliArgument("install");
plugin.execute();
plugin.verifyErrorFreeLog();
Verifier legacyPlugin = newVerifier(new File(directory, "legacy-plugin").getPath(), "remote");
legacyPlugin.addCliArgument("install");
legacyPlugin.execute();
legacyPlugin.verifyErrorFreeLog();

for (String color : new String[] {"never", "always"}) {
Verifier consumer = newVerifier(new File(directory, "consumer").getPath());
consumer.addCliArgument("-T2");
consumer.addCliArgument("-l");
consumer.addCliArgument("build.log");
consumer.addCliArgument("-B");
consumer.addCliArgument("--color=" + color);
consumer.addCliArgument("validate");
consumer.execute();
consumer.verifyErrorFreeLog();
for (String prefix : new String[] {"", "child/"}) {
Properties properties = consumer.loadProperties(prefix + "target/output-capabilities.properties");
Properties legacy = consumer.loadProperties(prefix + "target/legacy-output-capabilities.properties");
assertEquals("true", legacy.getProperty("available"));
assertEquals(properties.getProperty("destination"), legacy.getProperty("destination"));
assertEquals(properties.getProperty("encoding"), legacy.getProperty("encoding"));
// Maven 3 opens -l output with the JVM default charset.
assertEquals("FILE", properties.getProperty("destination"));
assertEquals(properties.getProperty("defaultEncoding"), properties.getProperty("encoding"));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public TestSuiteOrdering() {
suite.addTestSuite(MavenITmng7228LeakyModelTest.class);
suite.addTestSuite(MavenITmng7819FileLockingWithSnapshotsTest.class);
suite.addTestSuite(MavenITmng7587Jsr330.class);
suite.addTestSuite(MavenITOutputCapabilitiesTest.class);
suite.addTestSuite(MavenITmng7038RootdirTest.class);
suite.addTestSuite(MavenITmng7697PomWithEmojiTest.class);
suite.addTestSuite(MavenITmng7737ProfileActivationTest.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven.its.output</groupId>
<artifactId>consumer</artifactId>
<version>1.0</version>
</parent>
<artifactId>child</artifactId>
<packaging>pom</packaging>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.output</groupId>
<artifactId>consumer</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<modules>
<module>child</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.output</groupId>
<artifactId>legacy-output-capabilities-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<goals>
<goal>report</goal>
</goals>
<phase>validate</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>typed</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.output</groupId>
<artifactId>output-capabilities-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<goals>
<goal>report</goal>
</goals>
<phase>validate</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>legacy-only</id>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.output</groupId>
<artifactId>legacy-output-capabilities-maven-plugin</artifactId>
<version>1.0</version>
<packaging>maven-plugin</packaging>
<properties>
<maven.version>3.6.3</maven.version>
<maven.compiler.release>8</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.15.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.1</version>
</plugin>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.15.2</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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.
*/
package org.apache.maven.its.output;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

/** This fixture must compile and run using only Maven 3.6.3 APIs. */
@Mojo(name = "report", threadSafe = true)
public class LegacyOutputMojo extends AbstractMojo {
@Parameter(defaultValue = "${session}", readonly = true)
private MavenSession session;

@Parameter(defaultValue = "${project.build.directory}/legacy-output-capabilities.properties", readonly = true)
private File output;

@Parameter(property = "capabilities.available", defaultValue = "true")
private boolean expectedAvailable;

@Override
public void execute() throws MojoExecutionException {
Object value = session.getRequest().getData().get("maven.logging.outputCapabilities");
boolean available = value instanceof Map;
if (expectedAvailable != available) {
throw new MojoExecutionException("Unexpected compatibility service availability: " + available);
}
Properties properties = new Properties();
properties.setProperty("available", Boolean.toString(available));
properties.setProperty("destination", "UNKNOWN");
properties.setProperty("encoding", "unknown");
properties.setProperty("defaultEncoding", Charset.defaultCharset().name());
if (available) {
Map<?, ?> snapshot = new HashMap<>((Map<?, ?>) value);
Object destination = snapshot.get("destination");
if (Arrays.asList("CONSOLE", "FILE", "REDIRECTED", "UNKNOWN").contains(destination)) {
properties.setProperty("destination", (String) destination);
}
Object encoding = snapshot.get("encoding");
if (encoding instanceof String) {
properties.setProperty("encoding", (String) encoding);
}
}
try {
Files.createDirectories(output.toPath().getParent());
try (OutputStream stream = Files.newOutputStream(output.toPath())) {
properties.store(stream, "Maven logging compatibility information");
}
} catch (IOException e) {
throw new MojoExecutionException("Unable to write capabilities", e);
}
getLog().info("legacy-output-capabilities-marker caf\u00e9 \u251c\u2500");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.output</groupId>
<artifactId>output-capabilities-maven-plugin</artifactId>
<version>1.0</version>
<packaging>maven-plugin</packaging>
<properties>
<maven.version>3.10.0-SNAPSHOT</maven.version>
<maven.compiler.release>8</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.15.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.1</version>
</plugin>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.15.2</version>
</plugin>
</plugins>
</build>
</project>
Loading