Commit bef065e9 authored by Brian Long's avatar Brian Long
Browse files

docs and tidy up

parent ad4b06fc
Loading
Loading
Loading
Loading
+19 −12
Original line number Diff line number Diff line
@@ -88,9 +88,9 @@
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.13.2</version>
			<groupId>org.junit.jupiter</groupId>
			<artifactId>junit-jupiter-api</artifactId>
			<version>5.12.0</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
@@ -106,6 +106,16 @@
					<artifactId>maven-invoker-plugin</artifactId>
					<version>3.9.0</version>
				</plugin>
				<plugin>
					<groupId>org.eclipse.sisu</groupId>
					<artifactId>sisu-maven-plugin</artifactId>
					<version>0.9.0.M2</version>
				</plugin>
				<plugin>
					<groupId>org.codehaus.plexus</groupId>
					<artifactId>plexus-component-metadata</artifactId>
					<version>2.2.0</version>
				</plugin>
			</plugins>
		</pluginManagement>
		<plugins>
@@ -132,7 +142,6 @@
			<plugin>
				<groupId>org.eclipse.sisu</groupId>
				<artifactId>sisu-maven-plugin</artifactId>
				<version>0.3.5</version>
				<executions>
					<execution>
						<id>generate-index</id>
@@ -145,7 +154,6 @@
			<plugin>
				<groupId>org.codehaus.plexus</groupId>
				<artifactId>plexus-component-metadata</artifactId>
				<version>2.2.0</version>
				<executions>
					<execution>
						<goals>
@@ -210,7 +218,7 @@
			</build>
		</profile>
		<profile>
			<id>ossrh-release</id>
			<id>central-publish</id>
			<build>
				<plugins>
					<plugin>
@@ -247,14 +255,13 @@
						</executions>
					</plugin>
					<plugin>
						<groupId>org.sonatype.plugins</groupId>
						<artifactId>nexus-staging-maven-plugin</artifactId>
						<version>1.7.0</version>
						<groupId>org.sonatype.central</groupId>
						<artifactId>central-publishing-maven-plugin</artifactId>
						<version>0.8.0</version>
						<extensions>true</extensions>
						<configuration>
							<serverId>ossrh</serverId>
							<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
							<autoReleaseAfterClose>true</autoReleaseAfterClose>
							<publishingServerId>central</publishingServerId>
							<autoPublish>true</autoPublish>
						</configuration>
					</plugin>
				</plugins>
+31 −0
Original line number Diff line number Diff line
@@ -43,6 +43,37 @@ import org.slf4j.LoggerFactory;

import com.inteligr8.maven.model.ArtifactFilter;

/**
 * This class handles the parsing of the configuration specification supported
 * by this plugin.  It does not implement the banning execution; just the
 * collection of configurations to decide what artifacts should be banned.
 * 
 * The specification is as follows:
 * 
 * ```xml
 * <configuration>
 *   <import>
 *      <file>relative/path/file.xml</file>
 *      <url>https://host.domain/path/file.xml</url>
 *      <artifact>domain.host:artifact-id:[1.0,)</artifact>
 *   </import>
 *   <includes>
 *      <artifact>log4j:log4j</artifact>
 *      <artifact>org.apache.logging:log4j-impl:[,2.16.1)</artifact>
 *   </includes>
 *   <excludes>
 *      <artifact>...</artifact>
 *   </excludes>
 * </configuration>
 * ```
 * 
 * The imports are recursively processed under the same specification.  The
 * included artifacts are the ones that are banned.  Any artifact matching both
 * includes and excludes will be excluded and therefore NOT banned.
 * 
 * The `groupId` and `artifactId` of the standard shorthand Maven `artifact`
 * nomenclature may use regular expressions.
 */
public abstract class AbstractBanConfiguration implements BanConfiguration {
    
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+42 −2
Original line number Diff line number Diff line
@@ -31,10 +31,24 @@ import org.eclipse.aether.impl.VersionRangeResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * This class parses the a configuration file that conforms with the
 * specification defined by this plugin.
 */
public class BanConfigurationDownloader extends AbstractBanConfiguration {
    
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    
    /**
     * This constructs the downloader based on an accessible URL.
     * 
     * @param session A Maven session object.
     * @param artifactResolver A Maven Aether artifact resolver service.
     * @param versionRangeResolver A Maven Aether version range resolver service.
     * @param url The URL of a ban configuration file.
     * @throws IOException The file could not be downloaded for any number of reasons.
     * @throws MojoFailureException The file could not be parsed due to bad formatting or unexpected response.
     */
    public BanConfigurationDownloader(MavenSession session, ArtifactResolver artifactResolver, VersionRangeResolver versionRangeResolver, String url) throws IOException, MojoFailureException {
        super(session, artifactResolver, versionRangeResolver);
        
@@ -46,6 +60,16 @@ public class BanConfigurationDownloader extends AbstractBanConfiguration {
        }
    }

    /**
     * This constructs the downloader based on a file object.
     * 
     * @param session A Maven session object.
     * @param artifactResolver A Maven Aether artifact resolver service.
     * @param versionRangeResolver A Maven Aether version range resolver service.
     * @param file A file, typically local, though technically may be remote.
     * @throws IOException The file could not be read for any number of reasons.
     * @throws MojoFailureException The file could not be parsed due to bad formatting.
     */
    public BanConfigurationDownloader(MavenSession session, ArtifactResolver artifactResolver, VersionRangeResolver versionRangeResolver, File file) throws IOException, MojoFailureException {
        super(session, artifactResolver, versionRangeResolver);
        
@@ -57,6 +81,14 @@ public class BanConfigurationDownloader extends AbstractBanConfiguration {
        }
    }
    
    /**
     * This method loads the configuration from the specified URL.
     * 
     * @param url A URL of a ban configuration file.
     * @return A Maven Plexus XML DOM object.
     * @throws IOException The file could not be downloaded for any number of reasons.
     * @throws MojoFailureException The file could not be parsed due to bad formatting or unexpected response.
     */
    private Xpp3Dom load(URL url) throws IOException, XmlPullParserException {
        InputStream istream = url.openStream();
        BufferedInputStream bistream = new BufferedInputStream(istream, 16384);
@@ -68,6 +100,14 @@ public class BanConfigurationDownloader extends AbstractBanConfiguration {
        }
    }

    /**
     * This method loads the configuration from the specified file.
     * 
     * @param file A file, typically local, though technically may be remote.
     * @return A Maven Plexus XML DOM object.
     * @throws IOException The file could not be read for any number of reasons.
     * @throws MojoFailureException The file could not be parsed due to bad formatting.
     */
    private Xpp3Dom load(File file) throws IOException, XmlPullParserException {
        FileInputStream fistream = new FileInputStream(file);
        BufferedInputStream bistream = new BufferedInputStream(fistream, 16384);
+12 −0
Original line number Diff line number Diff line
@@ -28,6 +28,18 @@ import org.slf4j.LoggerFactory;

import com.inteligr8.maven.model.ArtifactFilter;

/**
 * This class implements the banned artifact detection logic.
 * 
 * It will recursively scan every dependency and plugin dependency to find any
 * artifacts that reference a banned artifact and its banned versions.  If one
 * is found, the filter will fail and stop the build immediately.  It will
 * prevent the banned artifact from being downloaded.
 * 
 * The complicated part is that when multiple versions of the same artifact
 * show up in the dependency tree, only one may be selected.  So this filter
 * will ignore the versions that are not selected.
 */
public class BanDependencyFilter implements DependencyFilter {
    
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
+4 −2
Original line number Diff line number Diff line
@@ -87,7 +87,9 @@ public class BanExtension extends AbstractMavenLifecycleParticipant {
        if (config == null)
            return;
        
        BanDependencyFilter depFilter = new BanDependencyFilter(config.getIncludeArtifacts(), config.getExcludeArtifacts());
        BanDependencyFilter depFilter = new BanDependencyFilter(
                config.getIncludeArtifacts(),
                config.getExcludeArtifacts());
        depFilter.setFailFast(true);

        MavenProject project = session.getCurrentProject();
@@ -132,7 +134,7 @@ public class BanExtension extends AbstractMavenLifecycleParticipant {
            return null;
        } else {
            try {
                return new BanConfigurationParser(session, this.artifactResolver, this.versionRangeResolver, plugin);
                return new BanPluginConfigurationParser(session, this.artifactResolver, this.versionRangeResolver, plugin);
            } catch (IOException | MojoFailureException e) {
                throw new MavenExecutionException(e.getMessage(), project.getFile());
            }
Loading