This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-jar-plugin.git
commit 571a8b3c7df6f84e35b26473525e2262b3e7b000 Author: Guillaume Nodet <[email protected]> AuthorDate: Tue Jun 18 10:04:04 2024 +0200 [MJAR-311] Switch to Maven 4 API --- .github/workflows/maven-verify.yml | 5 +- pom.xml | 92 ++++------- src/it/MJAR-228/verify.bsh | 5 +- src/it/MJAR-296-exclude-default/pom.xml | 56 ------- src/it/MJAR-296-exclude-default/setup.groovy | 29 ---- .../src/main/java/Foo.java | 23 --- src/it/MJAR-296-exclude-default/verify.groovy | 31 ---- src/it/MJAR-296-suppress-default-excludes/pom.xml | 59 ------- .../setup.groovy | 29 ---- .../verify.groovy | 33 ---- src/it/MJAR-307/pom.xml | 46 ------ .../MJAR-307/src/main/java/foo/project003/App.java | 48 ------ src/it/MJAR-307/verify.groovy | 25 --- src/it/MJAR-62-toolchain/invoker.properties | 18 --- src/it/MJAR-62-toolchain/pom.xml | 68 -------- .../src/main/java/myproject/HelloWorld.java | 53 ------ src/it/MJAR-62-toolchain/verify.groovy | 26 --- .../META-INF/plexus/components.xml | 101 ------------ .../apache/maven/plugins/jar/AbstractJarMojo.java | 179 +++++++++------------ .../java/org/apache/maven/plugins/jar/JarMojo.java | 19 +-- .../org/apache/maven/plugins/jar/Providers.java} | 31 +++- .../org/apache/maven/plugins/jar/TestJarMojo.java | 23 +-- .../plugins/jar/ToolchainsJdkSpecification.java | 110 ------------- src/site/site.xml | 6 +- src/site/xdoc/download.xml.vm | 117 ++++++++++---- .../org/apache/maven/plugins/jar/JarMojoTest.java | 15 +- .../plugins/jar/ToolchainsJdkVersionTest.java | 88 ---------- src/test/resources/unit/jar-basic-test/pom.xml | 9 +- 28 files changed, 252 insertions(+), 1092 deletions(-) diff --git a/.github/workflows/maven-verify.yml b/.github/workflows/maven-verify.yml index 065619b..56062b5 100644 --- a/.github/workflows/maven-verify.yml +++ b/.github/workflows/maven-verify.yml @@ -26,5 +26,6 @@ jobs: name: Verify uses: apache/maven-gh-actions-shared/.github/workflows/maven-verify.yml@v4 with: - maven4-enabled: true - + ff-maven: "4.0.0-beta-3" # Maven version for fail-fast-build + maven-matrix: '[ "4.0.0-beta-3" ]' + jdk-matrix: '[ "17", "21" ]' diff --git a/pom.xml b/pom.xml index fe1bb53..44b0092 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ </parent> <artifactId>maven-jar-plugin</artifactId> - <version>3.4.3-SNAPSHOT</version> + <version>4.0.0-SNAPSHOT</version> <packaging>maven-plugin</packaging> <name>Apache Maven JAR Plugin</name> @@ -73,119 +73,96 @@ </distributionManagement> <properties> - <javaVersion>8</javaVersion> - <mavenVersion>3.6.3</mavenVersion> - <mavenArchiverVersion>3.6.2</mavenArchiverVersion> + <javaVersion>17</javaVersion> + <mavenVersion>4.0.0-beta-3</mavenVersion> + + <guiceVersion>6.0.0</guiceVersion> + <junitVersion>5.10.1</junitVersion> + <mavenPluginPluginVersion>4.0.0-SNAPSHOT</mavenPluginPluginVersion> + <mavenArchiverVersion>4.0.0-SNAPSHOT</mavenArchiverVersion> + <mavenFileManagementVersion>3.1.0</mavenFileManagementVersion> + <mavenPluginTestingVersion>4.0.0-alpha-3-SNAPSHOT</mavenPluginTestingVersion> + <plexusArchiverVersion>4.9.2</plexusArchiverVersion> + + <version.maven-plugin-tools>${mavenPluginPluginVersion}</version.maven-plugin-tools> + <version.plexus-xml>4.0.3</version.plexus-xml> + <project.build.outputTimestamp>2024-06-16T12:09:50Z</project.build.outputTimestamp> </properties> <dependencyManagement> <dependencies> <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - <version>2.16.1</version> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + <version>32.0.1-jre</version> </dependency> </dependencies> </dependencyManagement> <dependencies> - <!-- Maven Core --> <dependency> <groupId>org.apache.maven</groupId> - <artifactId>maven-plugin-api</artifactId> + <artifactId>maven-api-core</artifactId> <version>${mavenVersion}</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.maven</groupId> - <artifactId>maven-core</artifactId> + <artifactId>maven-api-di</artifactId> <version>${mavenVersion}</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.maven</groupId> - <artifactId>maven-artifact</artifactId> + <artifactId>maven-api-meta</artifactId> <version>${mavenVersion}</version> <scope>provided</scope> </dependency> - - <!-- plugins annotations --> - <dependency> - <groupId>org.apache.maven.plugin-tools</groupId> - <artifactId>maven-plugin-annotations</artifactId> - <scope>provided</scope> - </dependency> - - <!-- Maven shared --> <dependency> <groupId>org.apache.maven.shared</groupId> <artifactId>file-management</artifactId> - <version>3.1.0</version> + <version>${mavenFileManagementVersion}</version> </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-archiver</artifactId> <version>${mavenArchiverVersion}</version> </dependency> - - <!-- plexus --> <dependency> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-archiver</artifactId> - <version>4.9.2</version> - </dependency> - - <!-- Other used dependencies --> - <dependency> - <groupId>javax.inject</groupId> - <artifactId>javax.inject</artifactId> - <version>1</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <version>1.7.36</version> + <version>${plexusArchiverVersion}</version> </dependency> <!-- Test --> <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> + <version>${junitVersion}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.maven.plugin-testing</groupId> <artifactId>maven-plugin-testing-harness</artifactId> - <version>4.0.0-alpha-2</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <version>4.11.0</version> + <version>${mavenPluginTestingVersion}</version> <scope>test</scope> </dependency> <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-junit-jupiter</artifactId> - <version>4.11.0</version> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <version>${mavenVersion}</version> <scope>test</scope> </dependency> <dependency> - <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-xml</artifactId> + <groupId>com.google.inject</groupId> + <artifactId>guice</artifactId> + <version>${guiceVersion}</version> <scope>test</scope> </dependency> </dependencies> <build> - <resources> - <resource> - <filtering>true</filtering> - <directory>src/main/filtered-resources</directory> - </resource> - </resources> <pluginManagement> <plugins> <plugin> @@ -219,13 +196,6 @@ </plugin> </plugins> </pluginManagement> - - <plugins> - <plugin> - <groupId>org.eclipse.sisu</groupId> - <artifactId>sisu-maven-plugin</artifactId> - </plugin> - </plugins> </build> <profiles> diff --git a/src/it/MJAR-228/verify.bsh b/src/it/MJAR-228/verify.bsh index 9fe1b9c..fc63447 100644 --- a/src/it/MJAR-228/verify.bsh +++ b/src/it/MJAR-228/verify.bsh @@ -51,8 +51,9 @@ try } if ( !"lib/junit-4.13.2.jar lib/hamcrest-core-1.3.jar".equals( manifest.get( Attributes.Name.CLASS_PATH ) ) ) { - System.err.println( Attributes.Name.CLASS_PATH.toString() + - " not equals lib/junit-4.13.2.jar lib/hamcrest-core-1.3.jar" ); + System.err.println( Attributes.Name.CLASS_PATH.toString() + + " equals '" + manifest.get( Attributes.Name.CLASS_PATH ) + "' " + + " but should be 'lib/junit-4.13.2.jar lib/hamcrest-core-1.3.jar'" ); return false; } diff --git a/src/it/MJAR-296-exclude-default/pom.xml b/src/it/MJAR-296-exclude-default/pom.xml deleted file mode 100644 index d3bc8c2..0000000 --- a/src/it/MJAR-296-exclude-default/pom.xml +++ /dev/null @@ -1,56 +0,0 @@ -<?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 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.maven.plugins</groupId> - <artifactId>mjar-296-exclude-default</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>jar</packaging> - <name>mjar-296-suppress-default-excludes</name> - <description>Verifies that the resulting jar not includes files excluded by default</description> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <project.build.outputTimestamp>2023-11-19T13:25:58Z</project.build.outputTimestamp> - </properties> - - <build> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-resources-plugin</artifactId> - <version>@version.maven-resources-plugin@</version> - <configuration> - <addDefaultExcludes>false</addDefaultExcludes> - </configuration> - </plugin> - </plugins> - </pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <version>@project.version@</version> - </plugin> - </plugins> - </build> -</project> diff --git a/src/it/MJAR-296-exclude-default/setup.groovy b/src/it/MJAR-296-exclude-default/setup.groovy deleted file mode 100644 index ab30042..0000000 --- a/src/it/MJAR-296-exclude-default/setup.groovy +++ /dev/null @@ -1,29 +0,0 @@ -import java.nio.file.Files -import java.nio.file.Paths - -/* - * 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. - */ - -// excluded files are not copied by m-invoker-p - so we need create one - -def resDir = basedir.toPath().resolve("src/main/resources") -Files.createDirectories(resDir) -Files.createFile(resDir.resolve(".cvsignore")) - -return true diff --git a/src/it/MJAR-296-exclude-default/src/main/java/Foo.java b/src/it/MJAR-296-exclude-default/src/main/java/Foo.java deleted file mode 100644 index 936ec41..0000000 --- a/src/it/MJAR-296-exclude-default/src/main/java/Foo.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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. - */ -public class Foo { - public static void main(String[] args) { - System.out.println("Hello World!"); - } -} diff --git a/src/it/MJAR-296-exclude-default/verify.groovy b/src/it/MJAR-296-exclude-default/verify.groovy deleted file mode 100644 index 9599b98..0000000 --- a/src/it/MJAR-296-exclude-default/verify.groovy +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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. - */ - -import java.util.jar.*; - -def target = new File(basedir, "target") - -def cvsignore = new File(target, "classes/.cvsignore") -assert cvsignore.exists() - -def artifact = new File(target, "mjar-296-exclude-default-1.0-SNAPSHOT.jar") -assert artifact.exists() - -def jar = new JarFile(artifact) -assert ".cvsignore" !in jar.entries()*.name diff --git a/src/it/MJAR-296-suppress-default-excludes/pom.xml b/src/it/MJAR-296-suppress-default-excludes/pom.xml deleted file mode 100644 index 0cd666c..0000000 --- a/src/it/MJAR-296-suppress-default-excludes/pom.xml +++ /dev/null @@ -1,59 +0,0 @@ -<?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 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.maven.plugins</groupId> - <artifactId>mjar-296-suppress-default-excludes</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>jar</packaging> - <name>mjar-296-suppress-default-excludes</name> - <description>Verifies that the resulting jar includes files excluded by default</description> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <project.build.outputTimestamp>2023-11-19T13:25:58Z</project.build.outputTimestamp> - </properties> - - <build> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-resources-plugin</artifactId> - <version>@version.maven-resources-plugin@</version> - <configuration> - <addDefaultExcludes>false</addDefaultExcludes> - </configuration> - </plugin> - </plugins> - </pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <version>@project.version@</version> - <configuration> - <addDefaultExcludes>false</addDefaultExcludes> - </configuration> - </plugin> - </plugins> - </build> -</project> diff --git a/src/it/MJAR-296-suppress-default-excludes/setup.groovy b/src/it/MJAR-296-suppress-default-excludes/setup.groovy deleted file mode 100644 index 324bf2b..0000000 --- a/src/it/MJAR-296-suppress-default-excludes/setup.groovy +++ /dev/null @@ -1,29 +0,0 @@ -import java.nio.file.Files -import java.nio.file.Path -import java.nio.file.Paths - -/* - * 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. - */ - -// excluded files are not copied by m-invoker-p - so we need create one -def resDir = basedir.toPath().resolve("src/main/resources") -Files.createDirectories(resDir) -Files.createFile(resDir.resolve(".cvsignore")) - -return true diff --git a/src/it/MJAR-296-suppress-default-excludes/verify.groovy b/src/it/MJAR-296-suppress-default-excludes/verify.groovy deleted file mode 100644 index 806c90e..0000000 --- a/src/it/MJAR-296-suppress-default-excludes/verify.groovy +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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. - */ - -import java.util.jar.*; - -def target = new File(basedir, "target") - -def cvsignore = new File(target, "classes/.cvsignore") -assert cvsignore.exists() - -def artifact = new File(target, "mjar-296-suppress-default-excludes-1.0-SNAPSHOT.jar") -assert artifact.exists() - -def jar = new JarFile(artifact) -assert ".cvsignore" in jar.entries()*.name - - diff --git a/src/it/MJAR-307/pom.xml b/src/it/MJAR-307/pom.xml deleted file mode 100644 index 88e9057..0000000 --- a/src/it/MJAR-307/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ -<?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 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <groupId>org.apache.maven.plugins.jar.it</groupId> - <artifactId>mjar-307</artifactId> - <version>1.0</version> - <packaging>jar</packaging> - <name>it-mjar-307</name> - - <description>Wrong version of commons-io cause a ClassNotFoundException: org.apache.commons.io.file.attribute.FileTimes</description> - - <properties> - <maven.build.timestamp.format>yyyyMMdd</maven.build.timestamp.format> - <project.build.outputTimestamp>${maven.build.timestamp}</project.build.outputTimestamp> - </properties> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <version>@project.version@</version> - </plugin> - </plugins> - </build> - -</project> diff --git a/src/it/MJAR-307/src/main/java/foo/project003/App.java b/src/it/MJAR-307/src/main/java/foo/project003/App.java deleted file mode 100644 index 3402dfd..0000000 --- a/src/it/MJAR-307/src/main/java/foo/project003/App.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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 foo.project003; - -/* - * 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. - */ - -/** - * Hello world! - * - */ -public class App { - public static void main(String[] args) { - System.out.println("Hello World!"); - } -} diff --git a/src/it/MJAR-307/verify.groovy b/src/it/MJAR-307/verify.groovy deleted file mode 100644 index d75e626..0000000 --- a/src/it/MJAR-307/verify.groovy +++ /dev/null @@ -1,25 +0,0 @@ -import java.util.jar.JarFile - -/* - * 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. - */ - -def target = new File( basedir, "target" ); -def jarFile = new File( target, "mjar-307-1.0.jar" ); - -assert jarFile.exists() diff --git a/src/it/MJAR-62-toolchain/invoker.properties b/src/it/MJAR-62-toolchain/invoker.properties deleted file mode 100644 index 9904dcc..0000000 --- a/src/it/MJAR-62-toolchain/invoker.properties +++ /dev/null @@ -1,18 +0,0 @@ -# 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. - -invoker.toolchain.jdk.version = 17 \ No newline at end of file diff --git a/src/it/MJAR-62-toolchain/pom.xml b/src/it/MJAR-62-toolchain/pom.xml deleted file mode 100644 index d226cca..0000000 --- a/src/it/MJAR-62-toolchain/pom.xml +++ /dev/null @@ -1,68 +0,0 @@ -<?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 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>mjar-62</artifactId> - <version>1.0-SNAPSHOT</version> - <packaging>jar</packaging> - <name>MJAR-62</name> - <organization> - <name>jar plugin it</name> - </organization> - - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.13.2</version> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-toolchains-plugin</artifactId> - <version>3.1.0</version> - <configuration> - <toolchains> - <jdk> - <version>17</version> - </jdk> - </toolchains> - </configuration> - <executions> - <execution> - <goals> - <goal>toolchain</goal> - </goals> - </execution> - </executions> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <version>@project.version@</version> - </plugin> - </plugins> - </build> -</project> diff --git a/src/it/MJAR-62-toolchain/src/main/java/myproject/HelloWorld.java b/src/it/MJAR-62-toolchain/src/main/java/myproject/HelloWorld.java deleted file mode 100644 index b156b77..0000000 --- a/src/it/MJAR-62-toolchain/src/main/java/myproject/HelloWorld.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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 myproject; - -/* - * 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. - */ - -/** - * The classic Hello World App. - */ -public class HelloWorld { - - /** - * Main method. - * - * @param args Not used - */ - public static void main(String[] args) { - System.out.println("Hi!"); - } -} diff --git a/src/it/MJAR-62-toolchain/verify.groovy b/src/it/MJAR-62-toolchain/verify.groovy deleted file mode 100644 index 4fdf714..0000000 --- a/src/it/MJAR-62-toolchain/verify.groovy +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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. - */ - -import java.util.jar.JarFile - -def mrjar = new JarFile(new File(basedir, 'target/mjar-62-1.0-SNAPSHOT.jar')) -def manifest = mrjar.manifest.mainAttributes - -assert manifest.getValue("Build-Jdk-Spec") == "17" -assert manifest.getValue("Build-Tool-Jdk-Spec") == System.getProperty("java.specification.version") diff --git a/src/main/filtered-resources/META-INF/plexus/components.xml b/src/main/filtered-resources/META-INF/plexus/components.xml deleted file mode 100644 index e428cbe..0000000 --- a/src/main/filtered-resources/META-INF/plexus/components.xml +++ /dev/null @@ -1,101 +0,0 @@ -<?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. ---> - -<component-set> - <components> - <!-- - | JAR - --> - <component> - <role>org.apache.maven.artifact.handler.ArtifactHandler</role> - <role-hint>jar</role-hint> - <implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation> - <configuration> - <type>jar</type> - <language>java</language> - <addedToClasspath>true</addedToClasspath> - </configuration> - </component> - <!-- - | TEST JAR - |--> - <component> - <role>org.apache.maven.artifact.handler.ArtifactHandler</role> - <role-hint>test-jar</role-hint> - <implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation> - <configuration> - <classifier>tests</classifier> - <extension>jar</extension> - <type>test-jar</type> - <packaging>jar</packaging> - <language>java</language> - <addedToClasspath>true</addedToClasspath> - </configuration> - </component> - - <!-- - | Defining the phases with their appropriate plugins - ! and versions which will be executed during the 'default' - ! life cycle. - --> - <component> - <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role> - <role-hint>jar</role-hint> - <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation> - <configuration> - <lifecycles> - <lifecycle> - <id>default</id> - <!-- START SNIPPET: jar-lifecycle --> - <phases> - <process-resources> - org.apache.maven.plugins:maven-resources-plugin:${version.maven-resources-plugin}:resources - </process-resources> - <compile> - org.apache.maven.plugins:maven-compiler-plugin:${version.maven-compiler-plugin}:compile - </compile> - <process-test-resources> - org.apache.maven.plugins:maven-resources-plugin:${version.maven-resources-plugin}:testResources - </process-test-resources> - <test-compile> - org.apache.maven.plugins:maven-compiler-plugin:${version.maven-compiler-plugin}:testCompile - </test-compile> - <test> - org.apache.maven.plugins:maven-surefire-plugin:${version.maven-surefire}:test - </test> - <package> - org.apache.maven.plugins:maven-jar-plugin:${project.version}:jar - </package> - <install> - org.apache.maven.plugins:maven-install-plugin:${version.maven-install-plugin}:install - </install> - <deploy> - org.apache.maven.plugins:maven-deploy-plugin:${version.maven-deploy-plugin}:deploy - </deploy> - </phases> - <!-- END SNIPPET: jar-lifecycle --> - </lifecycle> - </lifecycles> - </configuration> - </component> - - </components> -</component-set> diff --git a/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java b/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java index 9a2bc22..dc1cd10 100644 --- a/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java +++ b/src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java @@ -18,27 +18,29 @@ */ package org.apache.maven.plugins.jar; -import java.io.File; +import java.io.IOException; import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Arrays; import java.util.Map; -import java.util.Optional; - +import java.util.stream.Stream; + +import org.apache.maven.api.Artifact; +import org.apache.maven.api.Project; +import org.apache.maven.api.Session; +import org.apache.maven.api.di.Inject; +import org.apache.maven.api.plugin.Log; +import org.apache.maven.api.plugin.MojoException; +import org.apache.maven.api.plugin.annotations.Parameter; +import org.apache.maven.api.services.ProjectManager; import org.apache.maven.archiver.MavenArchiveConfiguration; import org.apache.maven.archiver.MavenArchiver; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.Component; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.MavenProjectHelper; +import org.apache.maven.archiver.MavenArchiverException; import org.apache.maven.shared.model.fileset.FileSet; import org.apache.maven.shared.model.fileset.util.FileSetManager; -import org.apache.maven.toolchain.ToolchainManager; import org.codehaus.plexus.archiver.Archiver; import org.codehaus.plexus.archiver.jar.JarArchiver; -import org.codehaus.plexus.archiver.util.DefaultFileSet; /** * Base class for creating a jar from project classes. @@ -46,7 +48,7 @@ import org.codehaus.plexus.archiver.util.DefaultFileSet; * @author <a href="[email protected]">Emmanuel Venisse</a> * @version $Id$ */ -public abstract class AbstractJarMojo extends AbstractMojo { +public abstract class AbstractJarMojo implements org.apache.maven.api.plugin.Mojo { private static final String[] DEFAULT_EXCLUDES = new String[] {"**/package.html"}; @@ -56,12 +58,6 @@ public abstract class AbstractJarMojo extends AbstractMojo { private static final String SEPARATOR = FileSystems.getDefault().getSeparator(); - @Component - private ToolchainsJdkSpecification toolchainsJdkSpecification; - - @Component - private ToolchainManager toolchainManager; - /** * List of files to include. Specified as fileset patterns which are relative to the input directory whose contents * is being packaged into the JAR. @@ -80,7 +76,7 @@ public abstract class AbstractJarMojo extends AbstractMojo { * Directory containing the generated JAR. */ @Parameter(defaultValue = "${project.build.directory}", required = true) - private File outputDirectory; + private Path outputDirectory; /** * Name of the generated JAR. @@ -91,20 +87,20 @@ public abstract class AbstractJarMojo extends AbstractMojo { /** * The Jar archiver. */ - @Component + @Inject private Map<String, Archiver> archivers; /** - * The {@link MavenProject}. + * The {@link Project}. */ - @Parameter(defaultValue = "${project}", readonly = true, required = true) - private MavenProject project; + @Inject + private Project project; /** - * The {@link MavenSession}. + * The {@link Session}. */ - @Parameter(defaultValue = "${session}", readonly = true, required = true) - private MavenSession session; + @Inject + private Session session; /** * The archive configuration to use. See <a href="http://maven.apache.org/shared/maven-archiver/index.html">Maven @@ -127,8 +123,8 @@ public abstract class AbstractJarMojo extends AbstractMojo { /** * */ - @Component - private MavenProjectHelper projectHelper; + @Inject + private ProjectManager projectManager; /** * Require the jar plugin to build a new JAR even if none of the contents appear to have changed. By default, this @@ -171,52 +167,30 @@ public abstract class AbstractJarMojo extends AbstractMojo { private boolean detectMultiReleaseJar; /** - * If set to {@code false}, the files and directories that by default are excluded from the resulting archive, - * like {@code .gitignore}, {@code .cvsignore} etc. will be included. - * This means all files like the following will be included. - * <ul> - * <li>Misc: **/*~, **/#*#, **/.#*, **/%*%, **/._*</li> - * <li>CVS: **/CVS, **/CVS/**, **/.cvsignore</li> - * <li>RCS: **/RCS, **/RCS/**</li> - * <li>SCCS: **/SCCS, **/SCCS/**</li> - * <li>VSSercer: **/vssver.scc</li> - * <li>MKS: **/project.pj</li> - * <li>SVN: **/.svn, **/.svn/**</li> - * <li>GNU: **/.arch-ids, **/.arch-ids/**</li> - * <li>Bazaar: **/.bzr, **/.bzr/**</li> - * <li>SurroundSCM: **/.MySCMServerInfo</li> - * <li>Mac: **/.DS_Store</li> - * <li>Serena Dimension: **/.metadata, **/.metadata/**</li> - * <li>Mercurial: **/.hg, **/.hg/**</li> - * <li>Git: **/.git, **/.git/**</li> - * <li>Bitkeeper: **/BitKeeper, **/BitKeeper/**, **/ChangeSet, - * **/ChangeSet/**</li> - * <li>Darcs: **/_darcs, **/_darcs/**, **/.darcsrepo, - * **/.darcsrepo/****/-darcs-backup*, **/.darcs-temp-mail - * </ul> - * - * @see <a href="https://codehaus-plexus.github.io/plexus-utils/apidocs/org/codehaus/plexus/util/AbstractScanner.html#DEFAULTEXCLUDES">DEFAULTEXCLUDES</a> - * - * @since 3.4.0 + * The mojo logger */ - @Parameter(defaultValue = "true") - private boolean addDefaultExcludes; + @Inject + private Log log; /** * Return the specific output directory to serve as the root for the archive. * @return get classes directory. */ - protected abstract File getClassesDirectory(); + protected abstract Path getClassesDirectory(); /** * Return the {@link #project MavenProject} * * @return the MavenProject. */ - protected final MavenProject getProject() { + protected final Project getProject() { return project; } + protected final Log getLog() { + return log; + } + /** * Overload this to produce a jar with another classifier, for example a test-jar. * @return get the classifier. @@ -237,7 +211,7 @@ public abstract class AbstractJarMojo extends AbstractMojo { * @param classifier an optional classifier * @return the file to generate */ - protected File getJarFile(File basedir, String resultFinalName, String classifier) { + protected Path getJarFile(Path basedir, String resultFinalName, String classifier) { if (basedir == null) { throw new IllegalArgumentException("basedir is not allowed to be null"); } @@ -247,20 +221,20 @@ public abstract class AbstractJarMojo extends AbstractMojo { String fileName = resultFinalName + (hasClassifier() ? "-" + classifier : "") + ".jar"; - return new File(basedir, fileName); + return basedir.resolve(fileName); } /** * Generates the JAR. * @return The instance of File for the created archive file. - * @throws MojoExecutionException in case of an error. + * @throws MojoException in case of an error. */ - public File createArchive() throws MojoExecutionException { - File jarFile = getJarFile(outputDirectory, finalName, getClassifier()); + public Path createArchive() throws MojoException { + Path jarFile = getJarFile(outputDirectory, finalName, getClassifier()); FileSetManager fileSetManager = new FileSetManager(); FileSet jarContentFileSet = new FileSet(); - jarContentFileSet.setDirectory(getClassesDirectory().getAbsolutePath()); + jarContentFileSet.setDirectory(getClassesDirectory().toAbsolutePath().toString()); jarContentFileSet.setIncludes(Arrays.asList(getIncludes())); jarContentFileSet.setExcludes(Arrays.asList(getExcludes())); @@ -289,18 +263,7 @@ public abstract class AbstractJarMojo extends AbstractMojo { MavenArchiver archiver = new MavenArchiver(); archiver.setCreatedBy("Maven JAR Plugin", "org.apache.maven.plugins", "maven-jar-plugin"); archiver.setArchiver((JarArchiver) archivers.get(archiverName)); - archiver.setOutputFile(jarFile); - - Optional.ofNullable(toolchainManager.getToolchainFromBuildContext("jdk", session)) - .ifPresent(toolchain -> toolchainsJdkSpecification - .getJDKSpecification(toolchain) - .ifPresent(jdkSpec -> { - archive.addManifestEntry("Build-Jdk-Spec", jdkSpec); - archive.addManifestEntry( - "Build-Tool-Jdk-Spec", System.getProperty("java.specification.version")); - archiver.setBuildJdkSpecDefaultEntry(false); - getLog().info("Set Build-Jdk-Spec based on toolchain in maven-jar-plugin " + toolchain); - })); + archiver.setOutputFile(jarFile.toFile()); // configure for Reproducible Builds based on outputTimestamp value archiver.configureReproducibleBuild(outputTimestamp); @@ -308,13 +271,13 @@ public abstract class AbstractJarMojo extends AbstractMojo { archive.setForced(forceCreation); try { - File contentDirectory = getClassesDirectory(); - if (!contentDirectory.exists()) { + Path contentDirectory = getClassesDirectory(); + if (!Files.exists(contentDirectory)) { if (!forceCreation) { getLog().warn("JAR will be empty - no content was marked for inclusion!"); } } else { - archiver.getArchiver().addFileSet(getFileSet(contentDirectory)); + archiver.getArchiver().addDirectory(contentDirectory.toFile(), getIncludes(), getExcludes()); } archiver.createArchive(session, project, archive); @@ -322,46 +285,60 @@ public abstract class AbstractJarMojo extends AbstractMojo { return jarFile; } catch (Exception e) { // TODO: improve error handling - throw new MojoExecutionException("Error assembling JAR", e); + throw new MojoException("Error assembling JAR", e); } } /** * Generates the JAR. - * @throws MojoExecutionException in case of an error. + * @throws MojoException in case of an error. */ @Override - public void execute() throws MojoExecutionException { + public void execute() throws MojoException { if (useDefaultManifestFile) { - throw new MojoExecutionException("You are using 'useDefaultManifestFile' which has been removed" + throw new MojoException("You are using 'useDefaultManifestFile' which has been removed" + " from the maven-jar-plugin. " + "Please see the >>Major Version Upgrade to version 3.0.0<< on the plugin site."); } - if (skipIfEmpty - && (!getClassesDirectory().exists() || getClassesDirectory().list().length < 1)) { + if (skipIfEmpty && isEmpty(getClassesDirectory())) { getLog().info("Skipping packaging of the " + getType()); } else { - File jarFile = createArchive(); - + Path jarFile = createArchive(); + Artifact artifact; if (hasClassifier()) { - projectHelper.attachArtifact(getProject(), getType(), getClassifier(), jarFile); + artifact = session.createArtifact( + project.getGroupId(), + project.getArtifactId(), + project.getVersion(), + getClassifier(), + null, + getType()); } else { if (projectHasAlreadySetAnArtifact()) { - throw new MojoExecutionException("You have to use a classifier " + throw new MojoException("You have to use a classifier " + "to attach supplemental artifacts to the project instead of replacing them."); } - getProject().getArtifact().setFile(jarFile); + artifact = project.getMainArtifact().get(); } + projectManager.attachArtifact(project, artifact, jarFile); } } - private boolean projectHasAlreadySetAnArtifact() { - if (getProject().getArtifact().getFile() == null) { - return false; + private boolean isEmpty(Path directory) { + if (!Files.isDirectory(directory)) { + return true; } + try (Stream<Path> children = Files.list(directory)) { + return !children.findAny().isPresent(); + } catch (IOException e) { + throw new MavenArchiverException("Unable to access directory", e); + } + } - return getProject().getArtifact().getFile().isFile(); + private boolean projectHasAlreadySetAnArtifact() { + Path path = projectManager.getPath(project).orElse(null); + return path != null && Files.isRegularFile(path); } /** @@ -386,14 +363,4 @@ public abstract class AbstractJarMojo extends AbstractMojo { } return DEFAULT_EXCLUDES; } - - private org.codehaus.plexus.archiver.FileSet getFileSet(File contentDirectory) { - DefaultFileSet fileSet = DefaultFileSet.fileSet(contentDirectory) - .prefixed("") - .includeExclude(getIncludes(), getExcludes()) - .includeEmptyDirs(true); - - fileSet.setUsingDefaultExcludes(addDefaultExcludes); - return fileSet; - } } diff --git a/src/main/java/org/apache/maven/plugins/jar/JarMojo.java b/src/main/java/org/apache/maven/plugins/jar/JarMojo.java index 7ce06d4..922634c 100644 --- a/src/main/java/org/apache/maven/plugins/jar/JarMojo.java +++ b/src/main/java/org/apache/maven/plugins/jar/JarMojo.java @@ -18,12 +18,10 @@ */ package org.apache.maven.plugins.jar; -import java.io.File; +import java.nio.file.Path; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.api.plugin.annotations.Mojo; +import org.apache.maven.api.plugin.annotations.Parameter; /** * Build a JAR from the current project. @@ -31,18 +29,13 @@ import org.apache.maven.plugins.annotations.ResolutionScope; * @author <a href="[email protected]">Emmanuel Venisse</a> * @version $Id$ */ -@Mojo( - name = "jar", - defaultPhase = LifecyclePhase.PACKAGE, - requiresProject = true, - threadSafe = true, - requiresDependencyResolution = ResolutionScope.RUNTIME) +@Mojo(name = "jar", defaultPhase = "package") public class JarMojo extends AbstractJarMojo { /** * Directory containing the classes and resource files that should be packaged into the JAR. */ @Parameter(defaultValue = "${project.build.outputDirectory}", required = true) - private File classesDirectory; + private Path classesDirectory; /** * Classifier to add to the artifact generated. If given, the artifact will be attached @@ -73,7 +66,7 @@ public class JarMojo extends AbstractJarMojo { * {@inheritDoc} */ @Override - protected File getClassesDirectory() { + protected Path getClassesDirectory() { return classesDirectory; } } diff --git a/src/it/MJAR-296-suppress-default-excludes/src/main/java/Foo.java b/src/main/java/org/apache/maven/plugins/jar/Providers.java similarity index 51% rename from src/it/MJAR-296-suppress-default-excludes/src/main/java/Foo.java rename to src/main/java/org/apache/maven/plugins/jar/Providers.java index 936ec41..b9a4acb 100644 --- a/src/it/MJAR-296-suppress-default-excludes/src/main/java/Foo.java +++ b/src/main/java/org/apache/maven/plugins/jar/Providers.java @@ -16,8 +16,33 @@ * specific language governing permissions and limitations * under the License. */ -public class Foo { - public static void main(String[] args) { - System.out.println("Hello World!"); +package org.apache.maven.plugins.jar; + +import org.apache.maven.api.Session; +import org.apache.maven.api.di.Named; +import org.apache.maven.api.di.Provides; +import org.apache.maven.api.services.ProjectManager; +import org.codehaus.plexus.archiver.Archiver; +import org.codehaus.plexus.archiver.jar.JarArchiver; +import org.codehaus.plexus.archiver.jar.JarToolModularJarArchiver; + +@Named +class Providers { + + @Named("jar") + @Provides + static Archiver jarArchiver() { + return new JarArchiver(); + } + + @Named("mjar") + @Provides + static Archiver mjarArchiver() { + return new JarToolModularJarArchiver(); + } + + @Provides + static ProjectManager projectManager(Session session) { + return session.getService(ProjectManager.class); } } diff --git a/src/main/java/org/apache/maven/plugins/jar/TestJarMojo.java b/src/main/java/org/apache/maven/plugins/jar/TestJarMojo.java index 96b5ac3..e3ec45a 100644 --- a/src/main/java/org/apache/maven/plugins/jar/TestJarMojo.java +++ b/src/main/java/org/apache/maven/plugins/jar/TestJarMojo.java @@ -18,13 +18,11 @@ */ package org.apache.maven.plugins.jar; -import java.io.File; +import java.nio.file.Path; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.api.plugin.MojoException; +import org.apache.maven.api.plugin.annotations.Mojo; +import org.apache.maven.api.plugin.annotations.Parameter; /** * Build a JAR of the test classes for the current project. @@ -33,12 +31,7 @@ import org.apache.maven.plugins.annotations.ResolutionScope; * @version $Id$ */ // CHECKSTYLE_OFF: LineLength -@Mojo( - name = "test-jar", - defaultPhase = LifecyclePhase.PACKAGE, - requiresProject = true, - threadSafe = true, - requiresDependencyResolution = ResolutionScope.TEST) +@Mojo(name = "test-jar", defaultPhase = "package") // CHECKSTYLE_ON: LineLength public class TestJarMojo extends AbstractJarMojo { @@ -53,7 +46,7 @@ public class TestJarMojo extends AbstractJarMojo { * Directory containing the test classes and resource files that should be packaged into the JAR. */ @Parameter(defaultValue = "${project.build.testOutputDirectory}", required = true) - private File testClassesDirectory; + private Path testClassesDirectory; /** * Classifier to use for {@code test-jar}. @@ -81,7 +74,7 @@ public class TestJarMojo extends AbstractJarMojo { * {@inheritDoc} */ @Override - protected File getClassesDirectory() { + protected Path getClassesDirectory() { return testClassesDirectory; } @@ -89,7 +82,7 @@ public class TestJarMojo extends AbstractJarMojo { * {@inheritDoc} */ @Override - public void execute() throws MojoExecutionException { + public void execute() throws MojoException { if (skip) { getLog().info("Skipping packaging of the test-jar"); } else { diff --git a/src/main/java/org/apache/maven/plugins/jar/ToolchainsJdkSpecification.java b/src/main/java/org/apache/maven/plugins/jar/ToolchainsJdkSpecification.java deleted file mode 100644 index ef992ab..0000000 --- a/src/main/java/org/apache/maven/plugins/jar/ToolchainsJdkSpecification.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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.plugins.jar; - -import javax.inject.Named; -import javax.inject.Singleton; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.UncheckedIOException; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -import org.apache.maven.toolchain.Toolchain; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Component provided JDK specification based on toolchains. - */ -@Named -@Singleton -class ToolchainsJdkSpecification { - - private final Logger logger = LoggerFactory.getLogger(ToolchainsJdkSpecification.class); - - private final Map<Path, String> cache = new HashMap<>(); - - public synchronized Optional<String> getJDKSpecification(Toolchain toolchain) { - Optional<Path> javacPath = getJavacPath(toolchain); - return javacPath.map(path -> cache.computeIfAbsent(path, this::getSpecForPath)); - } - - private Optional<Path> getJavacPath(Toolchain toolchain) { - return Optional.ofNullable(toolchain.findTool("javac")).map(Paths::get).map(this::getCanonicalPath); - } - - private Path getCanonicalPath(Path path) { - try { - return path.toRealPath(); - } catch (IOException e) { - if (path.getParent() != null) { - return getCanonicalPath(path.getParent()).resolve(path.getFileName()); - } else { - throw new UncheckedIOException(e); - } - } - } - - private String getSpecForPath(Path path) { - try { - ProcessBuilder processBuilder = new ProcessBuilder(path.toString(), "-version"); - processBuilder.redirectErrorStream(true); - Process process = processBuilder.start(); - String version = readOutput(process.getInputStream()).trim(); - process.waitFor(); - - if (version.startsWith("javac ")) { - version = version.substring(6); - if (version.startsWith("1.")) { - version = version.substring(0, 3); - } else { - version = version.substring(0, 2); - } - return version; - } else { - logger.warn("Unrecognized output from {}: {}", processBuilder.command(), version); - } - } catch (IndexOutOfBoundsException | IOException e) { - logger.warn("Failed to execute: {} - {}", path, e.getMessage()); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - } - - return null; - } - - private String readOutput(InputStream inputstream) throws IOException { - BufferedReader br = new BufferedReader(new InputStreamReader(inputstream)); - - StringBuilder output = new StringBuilder(); - String line; - while ((line = br.readLine()) != null) { - output.append(line + System.lineSeparator()); - } - - return output.toString(); - } -} diff --git a/src/site/site.xml b/src/site/site.xml index fcb02d6..38bb007 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -19,9 +19,9 @@ specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/DECORATION/1.8.1" +<project xmlns="http://maven.apache.org/DECORATION/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/DECORATION/1.8.1 http://maven.apache.org/xsd/decoration-1.8.1.xsd"> + xsi:schemaLocation="http://maven.apache.org/DECORATION/1.0.0 http://maven.apache.org/xsd/decoration-1.0.0.xsd"> <body> <menu name="Overview"> <item name="Introduction" href="index.html"/> @@ -29,7 +29,7 @@ under the License. <item name="Usage" href="usage.html"/> <item name="FAQ" href="faq.html"/> <!-- According to https://issues.apache.org/jira/browse/MNGSITE-152 --> - <item name="License" href="https://www.apache.org/licenses/"/> + <item name="License" href="http://www.apache.org/licenses/"/> <item name="Download" href="download.html"/> </menu> <menu name="Examples"> diff --git a/src/site/xdoc/download.xml.vm b/src/site/xdoc/download.xml.vm index 8f28f05..3f71035 100644 --- a/src/site/xdoc/download.xml.vm +++ b/src/site/xdoc/download.xml.vm @@ -23,51 +23,102 @@ under the License. <properties> <title>Download ${project.name} Source</title> </properties> - <body> <section name="Download ${project.name} ${project.version} Source"> - <p><strong>${project.name} ${project.version}</strong> is distributed in source format.</p> + <p>${project.name} ${project.version} is distributed in source format. Use a source archive if you intend to build + ${project.name} yourself. Otherwise, simply use the ready-made binary artifacts from central repository.</p> - <p>Use a source archive if you intend to build <strong>${project.name}</strong> yourself.</p> + <p>You will be prompted for a mirror - if the file is not found on yours, please be patient, as it may take 24 + hours to reach all mirrors.<p/> - <p>Otherwise, simply use the ready-made binary artifacts from <strong>central repository</strong>.</p> + <p>In order to guard against corrupted downloads/installations, it is highly recommended to + <a href="http://www.apache.org/dev/release-signing#verifying-signature">verify the signature</a> + of the release bundles against the public <a href="https://www.apache.org/dist/maven/KEYS">KEYS</a> used by the Apache Maven + developers.</p> - <p><strong>${project.name}</strong> is distributed under the <a href="https://www.apache.org/licenses/">Apache License, version 2.0</a>.</p> + <p>${project.name} is distributed under the <a href="http://www.apache.org/licenses/">Apache License, version 2.0</a>.</p> - <subsection name="Files"> - - <p>This is the current stable version of <strong>${project.name}</strong>.</p> - - <table> - <thead> - <tr> - <th></th> - <th>Link</th> - <th>Checksum</th> - <th>Signature</th> - </tr> - </thead> - <tbody> - <tr> - <td>${project.name} ${project.version} (Source zip)</td> - <td><a href="https://dlcdn.apache.org/maven/plugins/${project.artifactId}-${project.version}-source-release.zip">${project.artifactId}-${project.version}-source-release.zip</a></td> - <td><a href="https://downloads.apache.org/maven/plugins/${project.artifactId}-${project.version}-source-release.zip.sha512">${project.artifactId}-${project.version}-source-release.zip.sha512</a></td> - <td><a href="https://downloads.apache.org/maven/plugins/${project.artifactId}-${project.version}-source-release.zip.asc">${project.artifactId}-${project.version}-source-release.zip.asc</a></td> - </tr> - </tbody> - </table> - - <p>It is essential that you <a href="https://www.apache.org/info/verification.html">verify the integrity</a> of the downloaded file - using the checksum (.sha512 file) - or using the signature (.asc file) against the public <a href="https://downloads.apache.org/maven/KEYS">KEYS</a> used by the Apache Maven developers. + <p></p>We <b>strongly</b> encourage our users to configure a Maven repository mirror closer to their location, please read <a href="/guides/mini/guide-mirror-settings.html">How to Use Mirrors for Repositories</a>.</p> + + <a name="mirror"/> + <subsection name="Mirror"> + + <p> + [if-any logo] + <a href="[link]"> + <img align="right" src="[logo]" border="0" + alt="logo"/> + </a> + [end] + The currently selected mirror is + <b>[preferred]</b>. + If you encounter a problem with this mirror, + please select another mirror. + If all mirrors are failing, there are + <i>backup</i> + mirrors + (at the end of the mirrors list) that should be available. + </p> + + <form action="[location]" method="get" id="SelectMirror"> + Other mirrors: + <select name="Preferred"> + [if-any http] + [for http] + <option value="[http]">[http]</option> + [end] + [end] + [if-any ftp] + [for ftp] + <option value="[ftp]">[ftp]</option> + [end] + [end] + [if-any backup] + [for backup] + <option value="[backup]">[backup] (backup)</option> + [end] + [end] + </select> + <input type="submit" value="Change"/> + </form> + + <p> + You may also consult the + <a href="http://www.apache.org/mirrors/">complete list of + mirrors.</a> </p> </subsection> + + <subsection name="${project.name} ${project.version}"> + + <p>This is the current stable version of ${project.name}.</p> + + <table> + <thead> + <tr> + <th></th> + <th>Link</th> + <th>Checksum</th> + <th>Signature</th> + </tr> + </thead> + <tbody> + <tr> + <td>${project.name} ${project.version} (Source zip)</td> + <td><a href="[preferred]maven/plugins/${project.artifactId}-${project.version}-source-release.zip">maven/plugins/${project.artifactId}-${project.version}-source-release.zip</a></td> + <td><a href="https://www.apache.org/dist/maven/plugins/${project.artifactId}-${project.version}-source-release.zip.sha512">maven/plugins/${project.artifactId}-${project.version}-source-release.zip.sha512</a></td> + <td><a href="https://www.apache.org/dist/maven/plugins/${project.artifactId}-${project.version}-source-release.zip.asc">maven/plugins/${project.artifactId}-${project.version}-source-release.zip.asc</a></td> + </tr> + </tbody> + </table> + </subsection> <subsection name="Previous Versions"> - <p>It is strongly recommended to use the latest release version of <strong>${project.name}</strong> to take advantage of the newest features and bug fixes.</p> - <p>Older non-recommended releases can be found on our <a href="https://archive.apache.org/dist/maven/plugins/">archive site</a>.</p> + + <p>Older non-recommended releases can be found on our <a href="http://archive.apache.org/dist/maven/plugins/">archive site</a>.</p> + </subsection> </section> </body> diff --git a/src/test/java/org/apache/maven/plugins/jar/JarMojoTest.java b/src/test/java/org/apache/maven/plugins/jar/JarMojoTest.java index b8b57e8..9ac0406 100644 --- a/src/test/java/org/apache/maven/plugins/jar/JarMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/jar/JarMojoTest.java @@ -18,8 +18,9 @@ */ package org.apache.maven.plugins.jar; -import org.apache.maven.plugin.testing.junit5.InjectMojo; -import org.apache.maven.plugin.testing.junit5.MojoTest; +import org.apache.maven.api.plugin.testing.Basedir; +import org.apache.maven.api.plugin.testing.InjectMojo; +import org.apache.maven.api.plugin.testing.MojoTest; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -31,15 +32,19 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; * @version $Id$ */ @MojoTest -class JarMojoTest { +public class JarMojoTest { /** * Tests the discovery and configuration of the mojo. + * + * @throws Exception in case of an error */ @Test - @InjectMojo(goal = "jar", pom = "classpath:/unit/jar-basic-test/pom.xml") - void testJarTestEnvironment(JarMojo mojo) { + @Basedir("${basedir}/src/test/resources/unit/jar-basic-test") + @InjectMojo(goal = "jar") + public void testJarTestEnvironment(JarMojo mojo) throws Exception { assertNotNull(mojo); + assertEquals("foo", mojo.getProject().getGroupId()); } } diff --git a/src/test/java/org/apache/maven/plugins/jar/ToolchainsJdkVersionTest.java b/src/test/java/org/apache/maven/plugins/jar/ToolchainsJdkVersionTest.java deleted file mode 100644 index 0d504ed..0000000 --- a/src/test/java/org/apache/maven/plugins/jar/ToolchainsJdkVersionTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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.plugins.jar; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Locale; -import java.util.Optional; - -import org.apache.maven.toolchain.Toolchain; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import static org.mockito.Mockito.when; - -@ExtendWith(MockitoExtension.class) -class ToolchainsJdkVersionTest { - - @Mock - private Toolchain toolchain; - - private final ToolchainsJdkSpecification toolchainsJdkSpecification = new ToolchainsJdkSpecification(); - - @Test - void shouldReturnCorrectSpec() { - - Path javacPath = getJavacPath(); - Assumptions.assumeTrue(Files.isExecutable(javacPath)); - - when(toolchain.findTool("javac")).thenReturn(javacPath.toString()); - - Optional<String> jdkVersion = toolchainsJdkSpecification.getJDKSpecification(toolchain); - Assertions.assertTrue(jdkVersion.isPresent()); - Assertions.assertEquals(System.getProperty("java.specification.version"), jdkVersion.get()); - } - - @Test - void shouldReturnEmptySpec() { - - when(toolchain.findTool("javac")).thenReturn(null); - - Optional<String> jdkVersion = toolchainsJdkSpecification.getJDKSpecification(toolchain); - Assertions.assertFalse(jdkVersion.isPresent()); - } - - private String getJavaCName() { - if (System.getProperty("os.name", "").toLowerCase(Locale.ROOT).startsWith("win")) { - return "javac.exe"; - } else { - return "javac"; - } - } - - private Path getJavacPath() { - String javaCName = getJavaCName(); - - String javaHome = System.getProperty("java.home"); - - Path javacPath = Paths.get(javaHome, "bin", javaCName); - if (Files.isExecutable(javacPath)) { - return javacPath; - } - - // try with jre - return Paths.get(javaHome, "../bin", javaCName); - } -} diff --git a/src/test/resources/unit/jar-basic-test/pom.xml b/src/test/resources/unit/jar-basic-test/pom.xml index 5f5daa7..77306af 100644 --- a/src/test/resources/unit/jar-basic-test/pom.xml +++ b/src/test/resources/unit/jar-basic-test/pom.xml @@ -18,16 +18,13 @@ specific language governing permissions and limitations under the License. --> <project> + <groupId>foo</groupId> + <artifactId>bar</artifactId> <build> <plugins> <plugin> <artifactId>maven-jar-plugin</artifactId> - <configuration> - <project implementation="org.apache.maven.plugin.testing.stubs.MavenProjectStub"> - <groupId implementation="java.lang.String">foo</groupId> - <artifactId implementation="java.lang.String">bar</artifactId> - </project> - </configuration> + <configuration /> </plugin> </plugins> </build>
