You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2023/09/20 20:08:37 UTC
[maven-jdeprscan-plugin] 02/02: [MJDEPRSCAN-8] Reformat code
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch MJDEPRSCAN-8
in repository https://gitbox.apache.org/repos/asf/maven-jdeprscan-plugin.git
commit eb3c368e99508156d138ec1dc5ade365e5aaa64e
Author: Sylwester Lachiewicz <sl...@gmail.com>
AuthorDate: Wed Sep 20 22:08:26 2023 +0200
[MJDEPRSCAN-8] Reformat code
---
pom.xml | 262 ++++++-----
.../plugins/jdeprscan/AbstractJDeprScanMojo.java | 520 ++++++++++-----------
.../maven/plugins/jdeprscan/BaseJDeprScanMojo.java | 330 ++++++-------
.../maven/plugins/jdeprscan/JDeprScanMojo.java | 126 +++--
.../apache/maven/plugins/jdeprscan/ListMojo.java | 110 +++--
.../maven/plugins/jdeprscan/TestJDeprScanMojo.java | 126 +++--
.../jdeprscan/consumers/JDeprScanConsumer.java | 47 +-
.../jdeprscan/consumers/JDeprScanConsumerTest.java | 121 +++--
8 files changed, 775 insertions(+), 867 deletions(-)
diff --git a/pom.xml b/pom.xml
index 19deba1..6e2805b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,132 +1,130 @@
-<?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/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-plugins</artifactId>
- <version>39</version>
- <relativePath />
- </parent>
-
- <artifactId>maven-jdeprscan-plugin</artifactId>
- <version>3.0.0-SNAPSHOT</version>
- <packaging>maven-plugin</packaging>
-
- <name>Apache Maven JDeprScan Plugin</name>
- <description>The JDeprScan Plugin uses the jdeprscan tool that scans classes for uses of deprecated API elements.</description>
- <inceptionYear>2017</inceptionYear>
-
- <prerequisites>
- <maven>${mavenVersion}</maven>
- </prerequisites>
-
- <scm>
- <connection>scm:git:https://gitbox.apache.org/repos/asf/maven-jdeprscan-plugin.git</connection>
- <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-jdeprscan-plugin.git</developerConnection>
- <url>https://github.com/apache/maven-jdeprscan-plugin/tree/${project.scm.tag}</url>
- <tag>HEAD</tag>
- </scm>
- <issueManagement>
- <system>JIRA</system>
- <url>https://issues.apache.org/jira/browse/MJDEPRSCAN</url>
- </issueManagement>
- <ciManagement>
- <system>Jenkins</system>
- <url>https://ci-builds.apache.org/job/Maven/job/maven-box/job/maven-jdeprscan-plugin/</url>
- </ciManagement>
- <distributionManagement>
- <site>
- <id>apache.website</id>
- <url>scm:svn:https://svn.apache.org/repos/asf/maven/website/components/${maven.site.path}</url>
- </site>
- </distributionManagement>
-
- <properties>
- <mavenVersion>3.2.5</mavenVersion>
- <javaVersion>8</javaVersion>
- <project.build.outputTimestamp>2020-04-07T21:04:00Z</project.build.outputTimestamp>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.maven.plugin-tools</groupId>
- <artifactId>maven-plugin-annotations</artifactId>
- <scope>provided</scope>
- </dependency>
- <!-- Maven -->
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-plugin-api</artifactId>
- <version>${mavenVersion}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-core</artifactId>
- <version>${mavenVersion}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-model</artifactId>
- <version>${mavenVersion}</version>
- </dependency>
- <dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-utils</artifactId>
- <version>3.1.0</version>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <version>3.5</version>
- </dependency>
-
- <!-- TEST -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.13.2</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <profiles>
- <profile>
- <id>run-its</id>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-invoker-plugin</artifactId>
- <configuration>
- <projectsDirectory>src/it/projects</projectsDirectory>
- <pomIncludes>
- <include>*</include>
- </pomIncludes>
- </configuration>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-</project>
+<?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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugins</artifactId>
+ <version>39</version>
+ <relativePath />
+ </parent>
+
+ <artifactId>maven-jdeprscan-plugin</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ <packaging>maven-plugin</packaging>
+
+ <name>Apache Maven JDeprScan Plugin</name>
+ <description>The JDeprScan Plugin uses the jdeprscan tool that scans classes for uses of deprecated API elements.</description>
+ <inceptionYear>2017</inceptionYear>
+
+ <prerequisites>
+ <maven>${mavenVersion}</maven>
+ </prerequisites>
+
+ <scm>
+ <connection>scm:git:https://gitbox.apache.org/repos/asf/maven-jdeprscan-plugin.git</connection>
+ <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-jdeprscan-plugin.git</developerConnection>
+ <tag>HEAD</tag>
+ <url>https://github.com/apache/maven-jdeprscan-plugin/tree/${project.scm.tag}</url>
+ </scm>
+ <issueManagement>
+ <system>JIRA</system>
+ <url>https://issues.apache.org/jira/browse/MJDEPRSCAN</url>
+ </issueManagement>
+ <ciManagement>
+ <system>Jenkins</system>
+ <url>https://ci-builds.apache.org/job/Maven/job/maven-box/job/maven-jdeprscan-plugin/</url>
+ </ciManagement>
+ <distributionManagement>
+ <site>
+ <id>apache.website</id>
+ <url>scm:svn:https://svn.apache.org/repos/asf/maven/website/components/${maven.site.path}</url>
+ </site>
+ </distributionManagement>
+
+ <properties>
+ <mavenVersion>3.2.5</mavenVersion>
+ <javaVersion>8</javaVersion>
+ <project.build.outputTimestamp>2020-04-07T21:04:00Z</project.build.outputTimestamp>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-annotations</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <!-- Maven -->
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>${mavenVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <version>${mavenVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-model</artifactId>
+ <version>${mavenVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>3.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.5</version>
+ </dependency>
+
+ <!-- TEST -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.13.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>run-its</id>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <configuration>
+ <projectsDirectory>src/it/projects</projectsDirectory>
+ <pomIncludes>
+ <include>*</include>
+ </pomIncludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
diff --git a/src/main/java/org/apache/maven/plugins/jdeprscan/AbstractJDeprScanMojo.java b/src/main/java/org/apache/maven/plugins/jdeprscan/AbstractJDeprScanMojo.java
index 89071b4..9225e0b 100644
--- a/src/main/java/org/apache/maven/plugins/jdeprscan/AbstractJDeprScanMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jdeprscan/AbstractJDeprScanMojo.java
@@ -1,281 +1,239 @@
-package org.apache.maven.plugins.jdeprscan;
-
-/*
- * 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.io.File;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.StringTokenizer;
-
-import org.apache.commons.lang3.SystemUtils;
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.Component;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.toolchain.Toolchain;
-import org.apache.maven.toolchain.ToolchainManager;
-import org.codehaus.plexus.util.StringUtils;
-import org.codehaus.plexus.util.cli.CommandLineException;
-import org.codehaus.plexus.util.cli.CommandLineUtils;
-import org.codehaus.plexus.util.cli.Commandline;
-
-/**
- * Abstract class for all mojos
- *
- * @author Robert Scholte
- * @since 3.0.0
- */
-public abstract class AbstractJDeprScanMojo
- extends AbstractMojo
-{
- @Parameter( defaultValue = "${session}", readonly = true, required = true )
- private MavenSession session;
-
- @Component
- private ToolchainManager toolchainManager;
-
- @Override
- public void execute()
- throws MojoExecutionException, MojoFailureException
- {
- String jExecutable;
- try
- {
- jExecutable = getJDeprScanExecutable();
- }
- catch ( IOException e )
- {
- throw new MojoFailureException( "Unable to find jdeprscan command: " + e.getMessage(), e );
- }
-
- // Synopsis
- // jdeprscan [options] {dir|jar|class} ...
- Commandline cmd = new Commandline();
- cmd.setExecutable( jExecutable );
-
- addJDeprScanOptions( cmd );
-
- executeJDeprScanCommandLine( cmd, getConsumer() );
-
- verify();
- }
-
- protected CommandLineUtils.StringStreamConsumer getConsumer()
- {
- return null;
- }
-
- protected void verify() throws MojoExecutionException
- {
- }
-
- protected abstract boolean isForRemoval();
-
- protected void addJDeprScanOptions( Commandline cmd ) throws MojoFailureException
- {
- if ( isForRemoval() )
- {
- cmd.createArg().setValue( "--for-removal" );
- }
- }
-
- private String getJDeprScanExecutable()
- throws IOException
- {
- Toolchain tc = getToolchain();
-
- String jdeprscanExecutable = null;
- if ( tc != null )
- {
- jdeprscanExecutable = tc.findTool( "jdeprscan" );
- }
-
- String jdepsCommand = "jdeprscan" + ( SystemUtils.IS_OS_WINDOWS ? ".exe" : "" );
-
- File jdeprscanExe;
-
- if ( StringUtils.isNotEmpty( jdeprscanExecutable ) )
- {
- jdeprscanExe = new File( jdeprscanExecutable );
-
- if ( jdeprscanExe.isDirectory() )
- {
- jdeprscanExe = new File( jdeprscanExe, jdepsCommand );
- }
-
- if ( SystemUtils.IS_OS_WINDOWS && jdeprscanExe.getName().indexOf( '.' ) < 0 )
- {
- jdeprscanExe = new File( jdeprscanExe.getPath() + ".exe" );
- }
-
- if ( !jdeprscanExe.isFile() )
- {
- throw new IOException( "The jdeprscan executable '" + jdeprscanExe
- + "' doesn't exist or is not a file." );
- }
- return jdeprscanExe.getAbsolutePath();
- }
-
- jdeprscanExe =
- new File( SystemUtils.getJavaHome() + File.separator + ".." + File.separator + "sh", jdepsCommand );
-
- // ----------------------------------------------------------------------
- // Try to find jdepsExe from JAVA_HOME environment variable
- // ----------------------------------------------------------------------
- if ( !jdeprscanExe.exists() || !jdeprscanExe.isFile() )
- {
- Properties env = CommandLineUtils.getSystemEnvVars();
- String javaHome = env.getProperty( "JAVA_HOME" );
- if ( StringUtils.isEmpty( javaHome ) )
- {
- throw new IOException( "The environment variable JAVA_HOME is not correctly set." );
- }
- if ( ( !new File( javaHome ).getCanonicalFile().exists() )
- || ( new File( javaHome ).getCanonicalFile().isFile() ) )
- {
- throw new IOException( "The environment variable JAVA_HOME=" + javaHome
- + " doesn't exist or is not a valid directory." );
- }
-
- jdeprscanExe = new File( javaHome + File.separator + "bin", jdepsCommand );
- }
-
- if ( !jdeprscanExe.getCanonicalFile().exists() || !jdeprscanExe.getCanonicalFile().isFile() )
- {
- throw new IOException( "The jdeps executable '" + jdeprscanExe
- + "' doesn't exist or is not a file. Verify the JAVA_HOME environment variable." );
- }
-
- return jdeprscanExe.getAbsolutePath();
- }
-
- private void executeJDeprScanCommandLine( Commandline cmd,
- CommandLineUtils.StringStreamConsumer consumer )
- throws MojoExecutionException
- {
- if ( getLog().isDebugEnabled() )
- {
- // no quoted arguments
- getLog().debug( "Executing: " + CommandLineUtils.toString( cmd.getCommandline() ).replaceAll( "'", "" ) );
- }
-
- CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
- CommandLineUtils.StringStreamConsumer out;
- if ( consumer != null )
- {
- out = consumer;
- }
- else
- {
- out = new CommandLineUtils.StringStreamConsumer();
- }
-
- try
- {
- int exitCode = CommandLineUtils.executeCommandLine( cmd, out, err );
-
- String output = ( StringUtils.isEmpty( out.getOutput() ) ? null : '\n' + out.getOutput().trim() );
-
- if ( StringUtils.isNotEmpty( output ) )
- {
- getLog().info( output );
- }
-
- if ( exitCode != 0 )
- {
- StringBuilder msg = new StringBuilder( "\nExit code: " );
- msg.append( exitCode );
- if ( StringUtils.isNotEmpty( err.getOutput() ) )
- {
- msg.append( " - " ).append( err.getOutput() );
- }
- msg.append( '\n' );
- msg.append( "Command line was: " ).append( cmd ).append( '\n' ).append( '\n' );
-
- throw new MojoExecutionException( msg.toString() );
- }
-
- }
- catch ( CommandLineException e )
- {
- throw new MojoExecutionException( "Unable to execute jdeprscan command: " + e.getMessage(), e );
- }
-
- // ----------------------------------------------------------------------
- // Handle JDeprScan warnings
- // ----------------------------------------------------------------------
-
- if ( StringUtils.isNotEmpty( err.getOutput() ) && getLog().isWarnEnabled() )
- {
- getLog().warn( "JDeprScan Warnings" );
-
- StringTokenizer token = new StringTokenizer( err.getOutput(), "\n" );
- while ( token.hasMoreTokens() )
- {
- String current = token.nextToken().trim();
-
- getLog().warn( current );
- }
- }
- }
-
- private Toolchain getToolchain()
- {
- Toolchain tc = null;
- if ( toolchainManager != null )
- {
- tc = toolchainManager.getToolchainFromBuildContext( "jdk", session );
-
- if ( tc == null )
- {
- // Maven 3.3.0 has plugin execution scoped Toolchain Support
- try
- {
- Method getToolchainsMethod =
- toolchainManager.getClass().getMethod( "getToolchains", MavenSession.class, String.class,
- Map.class );
-
- @SuppressWarnings( "unchecked" )
- List<Toolchain> tcs =
- (List<Toolchain>) getToolchainsMethod.invoke( toolchainManager, session, "jdk",
- Collections.singletonMap( "version", "[9,)" ) );
-
- if ( tcs != null && tcs.size() > 0 )
- {
- // pick up latest, jdeps of JDK9 has more options compared to JDK8
- tc = tcs.get( tcs.size() - 1 );
- }
- }
- catch ( ReflectiveOperationException | SecurityException | IllegalArgumentException e )
- {
- // ignore
- }
- }
- }
-
- return tc;
- }
-}
+/*
+ * 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.jdeprscan;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import org.apache.commons.lang3.SystemUtils;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.toolchain.Toolchain;
+import org.apache.maven.toolchain.ToolchainManager;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+
+/**
+ * Abstract class for all mojos
+ *
+ * @author Robert Scholte
+ * @since 3.0.0
+ */
+public abstract class AbstractJDeprScanMojo extends AbstractMojo {
+ @Parameter(defaultValue = "${session}", readonly = true, required = true)
+ private MavenSession session;
+
+ @Component
+ private ToolchainManager toolchainManager;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ String jExecutable;
+ try {
+ jExecutable = getJDeprScanExecutable();
+ } catch (IOException e) {
+ throw new MojoFailureException("Unable to find jdeprscan command: " + e.getMessage(), e);
+ }
+
+ // Synopsis
+ // jdeprscan [options] {dir|jar|class} ...
+ Commandline cmd = new Commandline();
+ cmd.setExecutable(jExecutable);
+
+ addJDeprScanOptions(cmd);
+
+ executeJDeprScanCommandLine(cmd, getConsumer());
+
+ verify();
+ }
+
+ protected CommandLineUtils.StringStreamConsumer getConsumer() {
+ return null;
+ }
+
+ protected void verify() throws MojoExecutionException {}
+
+ protected abstract boolean isForRemoval();
+
+ protected void addJDeprScanOptions(Commandline cmd) throws MojoFailureException {
+ if (isForRemoval()) {
+ cmd.createArg().setValue("--for-removal");
+ }
+ }
+
+ private String getJDeprScanExecutable() throws IOException {
+ Toolchain tc = getToolchain();
+
+ String jdeprscanExecutable = null;
+ if (tc != null) {
+ jdeprscanExecutable = tc.findTool("jdeprscan");
+ }
+
+ String jdepsCommand = "jdeprscan" + (SystemUtils.IS_OS_WINDOWS ? ".exe" : "");
+
+ File jdeprscanExe;
+
+ if (StringUtils.isNotEmpty(jdeprscanExecutable)) {
+ jdeprscanExe = new File(jdeprscanExecutable);
+
+ if (jdeprscanExe.isDirectory()) {
+ jdeprscanExe = new File(jdeprscanExe, jdepsCommand);
+ }
+
+ if (SystemUtils.IS_OS_WINDOWS && jdeprscanExe.getName().indexOf('.') < 0) {
+ jdeprscanExe = new File(jdeprscanExe.getPath() + ".exe");
+ }
+
+ if (!jdeprscanExe.isFile()) {
+ throw new IOException(
+ "The jdeprscan executable '" + jdeprscanExe + "' doesn't exist or is not a file.");
+ }
+ return jdeprscanExe.getAbsolutePath();
+ }
+
+ jdeprscanExe =
+ new File(SystemUtils.getJavaHome() + File.separator + ".." + File.separator + "sh", jdepsCommand);
+
+ // ----------------------------------------------------------------------
+ // Try to find jdepsExe from JAVA_HOME environment variable
+ // ----------------------------------------------------------------------
+ if (!jdeprscanExe.exists() || !jdeprscanExe.isFile()) {
+ Properties env = CommandLineUtils.getSystemEnvVars();
+ String javaHome = env.getProperty("JAVA_HOME");
+ if (StringUtils.isEmpty(javaHome)) {
+ throw new IOException("The environment variable JAVA_HOME is not correctly set.");
+ }
+ if ((!new File(javaHome).getCanonicalFile().exists())
+ || (new File(javaHome).getCanonicalFile().isFile())) {
+ throw new IOException("The environment variable JAVA_HOME=" + javaHome
+ + " doesn't exist or is not a valid directory.");
+ }
+
+ jdeprscanExe = new File(javaHome + File.separator + "bin", jdepsCommand);
+ }
+
+ if (!jdeprscanExe.getCanonicalFile().exists()
+ || !jdeprscanExe.getCanonicalFile().isFile()) {
+ throw new IOException("The jdeps executable '" + jdeprscanExe
+ + "' doesn't exist or is not a file. Verify the JAVA_HOME environment variable.");
+ }
+
+ return jdeprscanExe.getAbsolutePath();
+ }
+
+ private void executeJDeprScanCommandLine(Commandline cmd, CommandLineUtils.StringStreamConsumer consumer)
+ throws MojoExecutionException {
+ if (getLog().isDebugEnabled()) {
+ // no quoted arguments
+ getLog().debug("Executing: "
+ + CommandLineUtils.toString(cmd.getCommandline()).replaceAll("'", ""));
+ }
+
+ CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
+ CommandLineUtils.StringStreamConsumer out;
+ if (consumer != null) {
+ out = consumer;
+ } else {
+ out = new CommandLineUtils.StringStreamConsumer();
+ }
+
+ try {
+ int exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
+
+ String output = (StringUtils.isEmpty(out.getOutput())
+ ? null
+ : '\n' + out.getOutput().trim());
+
+ if (StringUtils.isNotEmpty(output)) {
+ getLog().info(output);
+ }
+
+ if (exitCode != 0) {
+ StringBuilder msg = new StringBuilder("\nExit code: ");
+ msg.append(exitCode);
+ if (StringUtils.isNotEmpty(err.getOutput())) {
+ msg.append(" - ").append(err.getOutput());
+ }
+ msg.append('\n');
+ msg.append("Command line was: ").append(cmd).append('\n').append('\n');
+
+ throw new MojoExecutionException(msg.toString());
+ }
+
+ } catch (CommandLineException e) {
+ throw new MojoExecutionException("Unable to execute jdeprscan command: " + e.getMessage(), e);
+ }
+
+ // ----------------------------------------------------------------------
+ // Handle JDeprScan warnings
+ // ----------------------------------------------------------------------
+
+ if (StringUtils.isNotEmpty(err.getOutput()) && getLog().isWarnEnabled()) {
+ getLog().warn("JDeprScan Warnings");
+
+ StringTokenizer token = new StringTokenizer(err.getOutput(), "\n");
+ while (token.hasMoreTokens()) {
+ String current = token.nextToken().trim();
+
+ getLog().warn(current);
+ }
+ }
+ }
+
+ private Toolchain getToolchain() {
+ Toolchain tc = null;
+ if (toolchainManager != null) {
+ tc = toolchainManager.getToolchainFromBuildContext("jdk", session);
+
+ if (tc == null) {
+ // Maven 3.3.0 has plugin execution scoped Toolchain Support
+ try {
+ Method getToolchainsMethod = toolchainManager
+ .getClass()
+ .getMethod("getToolchains", MavenSession.class, String.class, Map.class);
+
+ @SuppressWarnings("unchecked")
+ List<Toolchain> tcs = (List<Toolchain>) getToolchainsMethod.invoke(
+ toolchainManager, session, "jdk", Collections.singletonMap("version", "[9,)"));
+
+ if (tcs != null && tcs.size() > 0) {
+ // pick up latest, jdeps of JDK9 has more options compared to JDK8
+ tc = tcs.get(tcs.size() - 1);
+ }
+ } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException e) {
+ // ignore
+ }
+ }
+ }
+
+ return tc;
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/jdeprscan/BaseJDeprScanMojo.java b/src/main/java/org/apache/maven/plugins/jdeprscan/BaseJDeprScanMojo.java
index b1fffda..3faa81b 100644
--- a/src/main/java/org/apache/maven/plugins/jdeprscan/BaseJDeprScanMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jdeprscan/BaseJDeprScanMojo.java
@@ -1,175 +1,155 @@
-package org.apache.maven.plugins.jdeprscan;
-
-/*
- * 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.io.File;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.maven.artifact.DependencyResolutionRequiredException;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.plugins.jdeprscan.consumers.JDeprScanConsumer;
-import org.apache.maven.project.MavenProject;
-import org.codehaus.plexus.util.StringUtils;
-import org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer;
-import org.codehaus.plexus.util.cli.Commandline;
-
-/**
- * Base class for all explicit jdeprscan mojos
- *
- * @author Robert Scholte
- * @since 3.0.0
- */
-public abstract class BaseJDeprScanMojo extends AbstractJDeprScanMojo
-{
- @Parameter( defaultValue = "${project}", readonly = true, required = true )
- private MavenProject project;
-
- /**
- * Indicates whether the build will continue even if there are jdeprscan warnings.
- */
- @Parameter( defaultValue = "true" )
- private boolean failOnWarning;
-
- /**
- * Limits scanning or listing to APIs that are deprecated for removal.
- * Can’t be used with a release value of 6, 7, or 8.
- */
- @Parameter( property = "maven.jdeprscan.forremoval" )
- private boolean forRemoval;
-
- /**
- * Specifies the Java SE release that provides the set of deprecated APIs for scanning.
- */
- @Parameter
- private String release;
-
- private final JDeprScanConsumer consumer = new JDeprScanConsumer();
-
- @Override
- public void execute()
- throws MojoExecutionException, MojoFailureException
- {
- if ( !Files.exists( getClassesDirectory() ) )
- {
- getLog().debug( "No classes to scan" );
- return;
- }
- super.execute();
- }
-
- protected MavenProject getProject()
- {
- return project;
- }
-
- @Override
- protected boolean isForRemoval()
- {
- return forRemoval;
- }
-
- @Override
- protected StringStreamConsumer getConsumer()
- {
- return consumer;
- }
-
- @Override
- protected final void addJDeprScanOptions( Commandline cmd ) throws MojoFailureException
- {
- super.addJDeprScanOptions( cmd );
-
- if ( release != null )
- {
- cmd.createArg().setValue( "--release" );
-
- cmd.createArg().setValue( release );
- }
-
- try
- {
- Collection<Path> cp = getClassPath();
-
- if ( !cp.isEmpty() )
- {
- cmd.createArg().setValue( "--class-path" );
-
- cmd.createArg().setValue( StringUtils.join( cp.iterator(), File.pathSeparator ) );
- }
-
- }
- catch ( DependencyResolutionRequiredException e )
- {
- throw new MojoFailureException( e.getMessage(), e );
- }
-
- cmd.createArg().setFile( getClassesDirectory().toFile() );
- }
-
- @Override
- protected void verify() throws MojoExecutionException
- {
- if ( !( consumer.getDeprecatedClasses().isEmpty() && consumer.getDeprecatedMethods().isEmpty() ) )
- {
- if ( !consumer.getDeprecatedClasses().isEmpty() )
- {
- getLog().warn( "Found usage of deprecated classes:" );
-
- for ( Map.Entry<String, Set<String>> classes : consumer.getDeprecatedClasses().entrySet() )
- {
- getLog().warn( "class " + classes.getKey() + " uses deprecated class(es)" );
- for ( String deprClass : classes.getValue() )
- {
- getLog().warn( " * " + deprClass );
- }
- }
- }
-
- if ( !consumer.getDeprecatedMethods().isEmpty() )
- {
- getLog().warn( "Found usage of deprecated methods:" );
-
- for ( Map.Entry<String, Set<String>> classes : consumer.getDeprecatedMethods().entrySet() )
- {
- getLog().warn( "class " + classes.getKey() + " uses deprecated method(s)" );
- for ( String deprMethod : classes.getValue() )
- {
- getLog().warn( " * " + deprMethod );
- }
- }
- }
-
- if ( failOnWarning )
- {
- throw new MojoExecutionException( "JDeprScan detected usage of deprecated classes/methods" );
- }
- }
- }
-
- protected abstract Path getClassesDirectory();
-
- protected abstract Collection<Path> getClassPath() throws DependencyResolutionRequiredException;
-}
+/*
+ * 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.jdeprscan;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.jdeprscan.consumers.JDeprScanConsumer;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.cli.CommandLineUtils.StringStreamConsumer;
+import org.codehaus.plexus.util.cli.Commandline;
+
+/**
+ * Base class for all explicit jdeprscan mojos
+ *
+ * @author Robert Scholte
+ * @since 3.0.0
+ */
+public abstract class BaseJDeprScanMojo extends AbstractJDeprScanMojo {
+ @Parameter(defaultValue = "${project}", readonly = true, required = true)
+ private MavenProject project;
+
+ /**
+ * Indicates whether the build will continue even if there are jdeprscan warnings.
+ */
+ @Parameter(defaultValue = "true")
+ private boolean failOnWarning;
+
+ /**
+ * Limits scanning or listing to APIs that are deprecated for removal.
+ * Can’t be used with a release value of 6, 7, or 8.
+ */
+ @Parameter(property = "maven.jdeprscan.forremoval")
+ private boolean forRemoval;
+
+ /**
+ * Specifies the Java SE release that provides the set of deprecated APIs for scanning.
+ */
+ @Parameter
+ private String release;
+
+ private final JDeprScanConsumer consumer = new JDeprScanConsumer();
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (!Files.exists(getClassesDirectory())) {
+ getLog().debug("No classes to scan");
+ return;
+ }
+ super.execute();
+ }
+
+ protected MavenProject getProject() {
+ return project;
+ }
+
+ @Override
+ protected boolean isForRemoval() {
+ return forRemoval;
+ }
+
+ @Override
+ protected StringStreamConsumer getConsumer() {
+ return consumer;
+ }
+
+ @Override
+ protected final void addJDeprScanOptions(Commandline cmd) throws MojoFailureException {
+ super.addJDeprScanOptions(cmd);
+
+ if (release != null) {
+ cmd.createArg().setValue("--release");
+
+ cmd.createArg().setValue(release);
+ }
+
+ try {
+ Collection<Path> cp = getClassPath();
+
+ if (!cp.isEmpty()) {
+ cmd.createArg().setValue("--class-path");
+
+ cmd.createArg().setValue(StringUtils.join(cp.iterator(), File.pathSeparator));
+ }
+
+ } catch (DependencyResolutionRequiredException e) {
+ throw new MojoFailureException(e.getMessage(), e);
+ }
+
+ cmd.createArg().setFile(getClassesDirectory().toFile());
+ }
+
+ @Override
+ protected void verify() throws MojoExecutionException {
+ if (!(consumer.getDeprecatedClasses().isEmpty()
+ && consumer.getDeprecatedMethods().isEmpty())) {
+ if (!consumer.getDeprecatedClasses().isEmpty()) {
+ getLog().warn("Found usage of deprecated classes:");
+
+ for (Map.Entry<String, Set<String>> classes :
+ consumer.getDeprecatedClasses().entrySet()) {
+ getLog().warn("class " + classes.getKey() + " uses deprecated class(es)");
+ for (String deprClass : classes.getValue()) {
+ getLog().warn(" * " + deprClass);
+ }
+ }
+ }
+
+ if (!consumer.getDeprecatedMethods().isEmpty()) {
+ getLog().warn("Found usage of deprecated methods:");
+
+ for (Map.Entry<String, Set<String>> classes :
+ consumer.getDeprecatedMethods().entrySet()) {
+ getLog().warn("class " + classes.getKey() + " uses deprecated method(s)");
+ for (String deprMethod : classes.getValue()) {
+ getLog().warn(" * " + deprMethod);
+ }
+ }
+ }
+
+ if (failOnWarning) {
+ throw new MojoExecutionException("JDeprScan detected usage of deprecated classes/methods");
+ }
+ }
+ }
+
+ protected abstract Path getClassesDirectory();
+
+ protected abstract Collection<Path> getClassPath() throws DependencyResolutionRequiredException;
+}
diff --git a/src/main/java/org/apache/maven/plugins/jdeprscan/JDeprScanMojo.java b/src/main/java/org/apache/maven/plugins/jdeprscan/JDeprScanMojo.java
index 2d85ff3..904c87a 100644
--- a/src/main/java/org/apache/maven/plugins/jdeprscan/JDeprScanMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jdeprscan/JDeprScanMojo.java
@@ -1,65 +1,61 @@
-package org.apache.maven.plugins.jdeprscan;
-
-/*
- * 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.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-import org.apache.maven.artifact.DependencyResolutionRequiredException;
-import org.apache.maven.plugins.annotations.LifecyclePhase;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.ResolutionScope;
-
-/**
- * Scans main classes with jdeprscan tool
- *
- * @author Robert Scholte
- * @since 3.0.0
- */
-@Mojo( name = "jdeprscan",
- requiresDependencyResolution = ResolutionScope.COMPILE,
- defaultPhase = LifecyclePhase.PROCESS_CLASSES,
- threadSafe = true )
-public class JDeprScanMojo extends BaseJDeprScanMojo
-{
- @Override
- protected Path getClassesDirectory()
- {
- return Paths.get( getProject().getBuild().getOutputDirectory() );
- }
-
- @Override
- protected Collection<Path> getClassPath()
- throws DependencyResolutionRequiredException
- {
- Set<Path> classPath = new LinkedHashSet<>( getProject().getCompileClasspathElements().size() );
-
- for ( String elm : getProject().getCompileClasspathElements() )
- {
- classPath.add( Paths.get( elm ) );
- }
-
- return Collections.unmodifiableSet( classPath );
- }
-}
+/*
+ * 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.jdeprscan;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+
+/**
+ * Scans main classes with jdeprscan tool
+ *
+ * @author Robert Scholte
+ * @since 3.0.0
+ */
+@Mojo(
+ name = "jdeprscan",
+ requiresDependencyResolution = ResolutionScope.COMPILE,
+ defaultPhase = LifecyclePhase.PROCESS_CLASSES,
+ threadSafe = true)
+public class JDeprScanMojo extends BaseJDeprScanMojo {
+ @Override
+ protected Path getClassesDirectory() {
+ return Paths.get(getProject().getBuild().getOutputDirectory());
+ }
+
+ @Override
+ protected Collection<Path> getClassPath() throws DependencyResolutionRequiredException {
+ Set<Path> classPath =
+ new LinkedHashSet<>(getProject().getCompileClasspathElements().size());
+
+ for (String elm : getProject().getCompileClasspathElements()) {
+ classPath.add(Paths.get(elm));
+ }
+
+ return Collections.unmodifiableSet(classPath);
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/jdeprscan/ListMojo.java b/src/main/java/org/apache/maven/plugins/jdeprscan/ListMojo.java
index d4a19d0..a2fa38f 100644
--- a/src/main/java/org/apache/maven/plugins/jdeprscan/ListMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jdeprscan/ListMojo.java
@@ -1,58 +1,52 @@
-package org.apache.maven.plugins.jdeprscan;
-
-/*
- * 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 org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.codehaus.plexus.util.cli.Commandline;
-
-/**
- * Prints the set of deprecated APIs. No scanning is done.
- *
- * @author Robert Scholte
- * @since 3.0.0
- */
-@Mojo( name = "list", requiresProject = false, requiresDirectInvocation = true )
-public class ListMojo
- extends AbstractJDeprScanMojo
-{
- /**
- * Limits scanning or listing to APIs that are deprecated for removal. Can’t be used with a release value of 6, 7,
- * or 8.
- */
- @Parameter( property = "for-removal" )
- private boolean forRemoval;
-
- @Override
- protected boolean isForRemoval()
- {
- return forRemoval;
- }
-
- @Override
- protected void addJDeprScanOptions( Commandline cmd )
- throws MojoFailureException
- {
- super.addJDeprScanOptions( cmd );
-
- cmd.createArg().setValue( "--list" );
- }
-}
+/*
+ * 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.jdeprscan;
+
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.codehaus.plexus.util.cli.Commandline;
+
+/**
+ * Prints the set of deprecated APIs. No scanning is done.
+ *
+ * @author Robert Scholte
+ * @since 3.0.0
+ */
+@Mojo(name = "list", requiresProject = false, requiresDirectInvocation = true)
+public class ListMojo extends AbstractJDeprScanMojo {
+ /**
+ * Limits scanning or listing to APIs that are deprecated for removal. Can’t be used with a release value of 6, 7,
+ * or 8.
+ */
+ @Parameter(property = "for-removal")
+ private boolean forRemoval;
+
+ @Override
+ protected boolean isForRemoval() {
+ return forRemoval;
+ }
+
+ @Override
+ protected void addJDeprScanOptions(Commandline cmd) throws MojoFailureException {
+ super.addJDeprScanOptions(cmd);
+
+ cmd.createArg().setValue("--list");
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/jdeprscan/TestJDeprScanMojo.java b/src/main/java/org/apache/maven/plugins/jdeprscan/TestJDeprScanMojo.java
index dc17851..6b2b2eb 100644
--- a/src/main/java/org/apache/maven/plugins/jdeprscan/TestJDeprScanMojo.java
+++ b/src/main/java/org/apache/maven/plugins/jdeprscan/TestJDeprScanMojo.java
@@ -1,65 +1,61 @@
-package org.apache.maven.plugins.jdeprscan;
-
-/*
- * 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.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-import org.apache.maven.artifact.DependencyResolutionRequiredException;
-import org.apache.maven.plugins.annotations.LifecyclePhase;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.ResolutionScope;
-
-/**
- * Scans test classes with jdeprscan
- *
- * @author Robert Scholte
- * @since 3.0.0
- */
-@Mojo( name = "test-jdeprscan",
- requiresDependencyResolution = ResolutionScope.TEST,
- defaultPhase = LifecyclePhase.PROCESS_TEST_CLASSES,
- threadSafe = true )
-public class TestJDeprScanMojo extends BaseJDeprScanMojo
-{
- @Override
- protected Path getClassesDirectory()
- {
- return Paths.get( getProject().getBuild().getTestOutputDirectory() );
- }
-
- @Override
- protected Collection<Path> getClassPath()
- throws DependencyResolutionRequiredException
- {
- Set<Path> classPath = new LinkedHashSet<>( getProject().getTestClasspathElements().size() );
-
- for ( String elm : getProject().getTestClasspathElements() )
- {
- classPath.add( Paths.get( elm ) );
- }
-
- return Collections.unmodifiableSet( classPath );
- }
-}
+/*
+ * 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.jdeprscan;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+
+/**
+ * Scans test classes with jdeprscan
+ *
+ * @author Robert Scholte
+ * @since 3.0.0
+ */
+@Mojo(
+ name = "test-jdeprscan",
+ requiresDependencyResolution = ResolutionScope.TEST,
+ defaultPhase = LifecyclePhase.PROCESS_TEST_CLASSES,
+ threadSafe = true)
+public class TestJDeprScanMojo extends BaseJDeprScanMojo {
+ @Override
+ protected Path getClassesDirectory() {
+ return Paths.get(getProject().getBuild().getTestOutputDirectory());
+ }
+
+ @Override
+ protected Collection<Path> getClassPath() throws DependencyResolutionRequiredException {
+ Set<Path> classPath =
+ new LinkedHashSet<>(getProject().getTestClasspathElements().size());
+
+ for (String elm : getProject().getTestClasspathElements()) {
+ classPath.add(Paths.get(elm));
+ }
+
+ return Collections.unmodifiableSet(classPath);
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/jdeprscan/consumers/JDeprScanConsumer.java b/src/main/java/org/apache/maven/plugins/jdeprscan/consumers/JDeprScanConsumer.java
index 5c20e43..78015eb 100644
--- a/src/main/java/org/apache/maven/plugins/jdeprscan/consumers/JDeprScanConsumer.java
+++ b/src/main/java/org/apache/maven/plugins/jdeprscan/consumers/JDeprScanConsumer.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.jdeprscan.consumers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.jdeprscan.consumers;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.jdeprscan.consumers;
import java.util.Collections;
import java.util.HashMap;
@@ -32,53 +31,45 @@ import org.codehaus.plexus.util.cli.StreamConsumer;
/**
* Consumes output of jdeprscan tool
- *
+ *
* @author Robert Scholte
* @since 3.0.0
*/
-public class JDeprScanConsumer
- extends CommandLineUtils.StringStreamConsumer
- implements StreamConsumer
-{
+public class JDeprScanConsumer extends CommandLineUtils.StringStreamConsumer implements StreamConsumer {
private final Map<String, Set<String>> deprecatedClasses = new HashMap<>();
private final Map<String, Set<String>> deprecatedMethods = new HashMap<>();
- public static final Pattern DEPRECATED_CLASS = Pattern.compile( "^class (\\S+) uses deprecated class (\\S+)" );
+ public static final Pattern DEPRECATED_CLASS = Pattern.compile("^class (\\S+) uses deprecated class (\\S+)");
- public static final Pattern DEPRECATED_METHOD = Pattern.compile( "^class (\\S+) uses deprecated method (\\S+)" );
+ public static final Pattern DEPRECATED_METHOD = Pattern.compile("^class (\\S+) uses deprecated method (\\S+)");
- public Map<String, Set<String>> getDeprecatedClasses( )
- {
- return Collections.unmodifiableMap( deprecatedClasses );
+ public Map<String, Set<String>> getDeprecatedClasses() {
+ return Collections.unmodifiableMap(deprecatedClasses);
}
- public Map<String, Set<String>> getDeprecatedMethods( )
- {
- return Collections.unmodifiableMap( deprecatedMethods );
+ public Map<String, Set<String>> getDeprecatedMethods() {
+ return Collections.unmodifiableMap(deprecatedMethods);
}
@Override
- public void consumeLine( String line )
- {
- super.consumeLine( line );
+ public void consumeLine(String line) {
+ super.consumeLine(line);
- Matcher deprecatedClassMatcher = DEPRECATED_CLASS.matcher( line );
- matcherCollector( deprecatedClassMatcher, deprecatedClasses );
+ Matcher deprecatedClassMatcher = DEPRECATED_CLASS.matcher(line);
+ matcherCollector(deprecatedClassMatcher, deprecatedClasses);
- Matcher deprecatedMethodMatcher = DEPRECATED_METHOD.matcher( line );
- matcherCollector( deprecatedMethodMatcher, deprecatedMethods );
+ Matcher deprecatedMethodMatcher = DEPRECATED_METHOD.matcher(line);
+ matcherCollector(deprecatedMethodMatcher, deprecatedMethods);
}
- private void matcherCollector( Matcher matcher, Map<String, Set<String>> deprecatedMethods )
- {
- if ( !matcher.find() )
- {
+ private void matcherCollector(Matcher matcher, Map<String, Set<String>> deprecatedMethods) {
+ if (!matcher.find()) {
return;
}
- Set<String> dm = deprecatedMethods.computeIfAbsent( matcher.group( 1 ), k -> new HashSet<>() );
- dm.add( matcher.group( 2 ) );
+ Set<String> dm = deprecatedMethods.computeIfAbsent(matcher.group(1), k -> new HashSet<>());
+ dm.add(matcher.group(2));
}
}
diff --git a/src/test/java/org/apache/maven/plugins/jdeprscan/consumers/JDeprScanConsumerTest.java b/src/test/java/org/apache/maven/plugins/jdeprscan/consumers/JDeprScanConsumerTest.java
index 0126ddb..3f4d563 100644
--- a/src/test/java/org/apache/maven/plugins/jdeprscan/consumers/JDeprScanConsumerTest.java
+++ b/src/test/java/org/apache/maven/plugins/jdeprscan/consumers/JDeprScanConsumerTest.java
@@ -1,63 +1,58 @@
-package org.apache.maven.plugins.jdeprscan.consumers;
-
-/*
- * 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 static org.junit.Assert.assertEquals;
-
-import java.util.Collections;
-import java.util.Set;
-
-import org.junit.Before;
-import org.junit.Test;
-
-public class JDeprScanConsumerTest
-{
- private JDeprScanConsumer consumer;
-
- @Before
- public void setUp()
- {
- consumer = new JDeprScanConsumer();
- }
-
- @Test
- public void testDeprecatedClass()
- {
- consumer.consumeLine( "class o/a/m/p/j/its/Deprecations uses deprecated class java/rmi/RMISecurityManager " );
-
- assertEquals( consumer.getDeprecatedClasses().size(), 1 );
- assertEquals( consumer.getDeprecatedMethods().size(), 0 );
-
- Set<String> classes = consumer.getDeprecatedClasses().get( "o/a/m/p/j/its/Deprecations" );
- assertEquals( Collections.singleton( "java/rmi/RMISecurityManager" ), classes );
- }
-
- @Test
- public void testDeprecatedMethod()
- {
- consumer.consumeLine( "class o/a/m/p/j/its/Deprecations uses deprecated method java/lang/Boolean::<init>(Z)V" );
-
- assertEquals( consumer.getDeprecatedClasses().size(), 0 );
- assertEquals( consumer.getDeprecatedMethods().size(), 1 );
-
- Set<String> methods = consumer.getDeprecatedMethods().get( "o/a/m/p/j/its/Deprecations" );
- assertEquals( Collections.singleton( "java/lang/Boolean::<init>(Z)V" ), methods );
- }
-}
+/*
+ * 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.jdeprscan.consumers;
+
+import java.util.Collections;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class JDeprScanConsumerTest {
+ private JDeprScanConsumer consumer;
+
+ @Before
+ public void setUp() {
+ consumer = new JDeprScanConsumer();
+ }
+
+ @Test
+ public void testDeprecatedClass() {
+ consumer.consumeLine("class o/a/m/p/j/its/Deprecations uses deprecated class java/rmi/RMISecurityManager ");
+
+ assertEquals(consumer.getDeprecatedClasses().size(), 1);
+ assertEquals(consumer.getDeprecatedMethods().size(), 0);
+
+ Set<String> classes = consumer.getDeprecatedClasses().get("o/a/m/p/j/its/Deprecations");
+ assertEquals(Collections.singleton("java/rmi/RMISecurityManager"), classes);
+ }
+
+ @Test
+ public void testDeprecatedMethod() {
+ consumer.consumeLine("class o/a/m/p/j/its/Deprecations uses deprecated method java/lang/Boolean::<init>(Z)V");
+
+ assertEquals(consumer.getDeprecatedClasses().size(), 0);
+ assertEquals(consumer.getDeprecatedMethods().size(), 1);
+
+ Set<String> methods = consumer.getDeprecatedMethods().get("o/a/m/p/j/its/Deprecations");
+ assertEquals(Collections.singleton("java/lang/Boolean::<init>(Z)V"), methods);
+ }
+}