From 4554d909378ddbd323ad3d50727ae4b8a9eb1d65 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Sat, 7 Oct 2023 12:58:53 +0200 Subject: [PATCH] Remove support for listing directory as html page and cleanups - remove listing directory - remove not implemented doDelete http method - add missing override annotation - remove unused methods --- .../codehaus/mojo/mrm/api/AbstractEntry.java | 36 +-- .../codehaus/mojo/mrm/api/BaseFileEntry.java | 6 - .../codehaus/mojo/mrm/api/BaseFileSystem.java | 46 +--- .../mojo/mrm/api/DefaultDirectoryEntry.java | 10 +- .../java/org/codehaus/mojo/mrm/api/Entry.java | 3 +- .../org/codehaus/mojo/mrm/api/FileSystem.java | 36 +-- .../codehaus/mojo/mrm/api/ResolverUtils.java | 4 + .../codehaus/mojo/mrm/api/maven/Artifact.java | 14 +- .../mojo/mrm/api/maven/ArtifactStore.java | 3 +- .../mojo/mrm/api/maven/BaseArtifactStore.java | 16 +- .../mojo/mrm/plugin/AbstractMRMMojo.java | 3 +- .../mojo/mrm/plugin/AbstractStartMojo.java | 2 +- .../mojo/mrm/plugin/ConsoleScanner.java | 4 +- .../mojo/mrm/plugin/FileSystemServer.java | 6 +- .../codehaus/mojo/mrm/plugin/ProxyRepo.java | 7 +- .../org/codehaus/mojo/mrm/plugin/RunMojo.java | 8 +- .../codehaus/mojo/mrm/plugin/StartMojo.java | 7 +- .../codehaus/mojo/mrm/plugin/StopMojo.java | 8 +- .../mrm/impl/GenerateOnErrorFileEntry.java | 19 +- .../codehaus/mojo/mrm/impl/LinkFileEntry.java | 19 +- .../mojo/mrm/impl/RemoteFileEntry.java | 77 ------ .../org/codehaus/mojo/mrm/impl/Utils.java | 222 ------------------ .../mrm/impl/digest/AutoDigestFileSystem.java | 12 +- .../mrm/impl/digest/MD5DigestFileEntry.java | 28 +-- .../mrm/impl/digest/SHA1DigestFileEntry.java | 28 +-- .../impl/maven/ArchetypeCatalogFileEntry.java | 19 +- .../mrm/impl/maven/ArtifactFileEntry.java | 29 +-- .../impl/maven/CompositeArtifactStore.java | 42 +--- .../mrm/impl/maven/DiskArtifactStore.java | 42 +--- .../impl/maven/FileSystemArtifactStore.java | 43 +--- .../mrm/impl/maven/MetadataFileEntry.java | 19 +- .../mrm/impl/maven/MockArtifactStore.java | 75 ++---- .../mojo/mrm/servlet/FileSystemServlet.java | 135 +---------- 33 files changed, 131 insertions(+), 897 deletions(-) delete mode 100644 mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/RemoteFileEntry.java diff --git a/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/AbstractEntry.java b/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/AbstractEntry.java index 58025cf8..ea54b706 100644 --- a/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/AbstractEntry.java +++ b/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/AbstractEntry.java @@ -22,18 +22,10 @@ /** * Abstract implementation of {@link Entry}. * - * @serial * @since 1.0 */ public abstract class AbstractEntry implements Entry { - /** - * Ensure consistent serialization. - * - * @since 1.0 - */ - private static final long serialVersionUID = 1L; - /** * The file system that this entry belongs to. * @@ -69,30 +61,22 @@ protected AbstractEntry(FileSystem fileSystem, DirectoryEntry parent, String nam this.name = name; } - /** - * {@inheritDoc} - */ + @Override public FileSystem getFileSystem() { return fileSystem; } - /** - * {@inheritDoc} - */ + @Override public DirectoryEntry getParent() { return parent; } - /** - * {@inheritDoc} - */ + @Override public String getName() { return name; } - /** - * {@inheritDoc} - */ + @Override public boolean equals(Object o) { if (this == o) { return true; @@ -112,18 +96,14 @@ public boolean equals(Object o) { return Objects.equals(parent, abstractEntry.parent); } - /** - * {@inheritDoc} - */ + @Override public final int hashCode() { int result = name.hashCode(); result = 31 * result + (parent != null ? parent.hashCode() : 0); return result; } - /** - * {@inheritDoc} - */ + @Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("Entry["); @@ -132,9 +112,7 @@ public String toString() { return sb.toString(); } - /** - * {@inheritDoc} - */ + @Override public final String toPath() { Stack stack = new Stack<>(); Entry root = getFileSystem().getRoot(); diff --git a/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/BaseFileEntry.java b/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/BaseFileEntry.java index 895fab47..dff316d4 100644 --- a/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/BaseFileEntry.java +++ b/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/BaseFileEntry.java @@ -22,12 +22,6 @@ * @since 1.0 */ public abstract class BaseFileEntry extends AbstractEntry implements FileEntry { - /** - * Ensure consistent serialization. - * - * @since 1.0 - */ - private static final long serialVersionUID = 1L; /** * Creates an entry in the specified file system with the specified parent and name. diff --git a/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/BaseFileSystem.java b/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/BaseFileSystem.java index 3a0ae3d5..e56ce66b 100644 --- a/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/BaseFileSystem.java +++ b/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/BaseFileSystem.java @@ -16,38 +16,24 @@ package org.codehaus.mojo.mrm.api; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; - /** * Base implementation of {@link FileSystem} that all implementations should extend from. * * @since 1.0 */ public abstract class BaseFileSystem implements FileSystem { - /** - * Ensure consistent serialization. - * - * @since 1.0 - */ - private static final long serialVersionUID = 1L; /** * The root entry. */ private final DirectoryEntry root = new DefaultDirectoryEntry(this, null, ""); - /** - * {@inheritDoc} - */ + @Override public DirectoryEntry getRoot() { return root; } - /** - * {@inheritDoc} - */ + @Override public Entry get(String path) { if (path.startsWith("/")) { path = path.substring(1); @@ -87,32 +73,4 @@ protected Entry get(DirectoryEntry parent, String name) { } return null; } - - /** - * {@inheritDoc} - */ - public DirectoryEntry mkdir(DirectoryEntry parent, String name) { - throw new UnsupportedOperationException(); - } - - /** - * {@inheritDoc} - */ - public FileEntry put(DirectoryEntry parent, String name, InputStream content) throws IOException { - throw new UnsupportedOperationException(); - } - - /** - * {@inheritDoc} - */ - public FileEntry put(DirectoryEntry parent, String name, byte[] content) throws IOException { - return put(parent, name, new ByteArrayInputStream(content)); - } - - /** - * {@inheritDoc} - */ - public void remove(Entry entry) { - throw new UnsupportedOperationException(); - } } diff --git a/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/DefaultDirectoryEntry.java b/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/DefaultDirectoryEntry.java index 95a3d640..bd85e896 100644 --- a/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/DefaultDirectoryEntry.java +++ b/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/DefaultDirectoryEntry.java @@ -24,12 +24,6 @@ * @since 1.0 */ public class DefaultDirectoryEntry extends AbstractEntry implements DirectoryEntry { - /** - * Ensure consistent serialization. - * - * @since 1.0 - */ - private static final long serialVersionUID = 1L; /** * Creates an entry in the specified file system with the specified parent and name. @@ -62,9 +56,7 @@ public static DirectoryEntry equivalent(FileSystem target, DirectoryEntry direct return new DefaultDirectoryEntry(target, equivalent(target, directory.getParent()), directory.getName()); } - /** - * {@inheritDoc} - */ + @Override public long getLastModified() throws IOException { return getFileSystem().getLastModified(this); } diff --git a/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/Entry.java b/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/Entry.java index 54a4f3e8..43b670b2 100644 --- a/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/Entry.java +++ b/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/Entry.java @@ -16,14 +16,13 @@ package org.codehaus.mojo.mrm.api; import java.io.IOException; -import java.io.Serializable; /** * An entry in the repository. * * @since 1.0 */ -public interface Entry extends Serializable { +public interface Entry { /** * Returns the repository that this entry belongs to. diff --git a/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/FileSystem.java b/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/FileSystem.java index 22be5867..f9c4022f 100644 --- a/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/FileSystem.java +++ b/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/FileSystem.java @@ -18,14 +18,13 @@ import java.io.IOException; import java.io.InputStream; -import java.io.Serializable; /** * A repository is just a type of file system. * * @since 1.0 */ -public interface FileSystem extends Serializable { +public interface FileSystem { /** * Lists the entries in the specified directory. Some implementations may be lazy caching * implementations, in which case it is permitted to return either an empty array, or only those entries which @@ -73,17 +72,6 @@ public interface FileSystem extends Serializable { */ long getLastModified(DirectoryEntry entry) throws IOException; - /** - * Makes the specified child directory. - * - * @param parent the directory in which the child is to be created. - * @param name the name of the child directory. - * @return the child directory entry. - * @throws UnsupportedOperationException if the repository is read-only. - * @since 1.0 - */ - DirectoryEntry mkdir(DirectoryEntry parent, String name); - /** * Puts the specified content into a the specified directory. * @@ -96,26 +84,4 @@ public interface FileSystem extends Serializable { * @since 1.0 */ FileEntry put(DirectoryEntry parent, String name, InputStream content) throws IOException; - - /** - * Puts the specified content into a the specified directory. - * - * @param parent the directory in which the content is to be created/updated. - * @param name the name of the file. - * @param content the content. - * @return the {@link FileEntry} that was created/updated. - * @throws UnsupportedOperationException if the repository is read-only. - * @throws java.io.IOException if the content could not be read/written. - * @since 1.0 - */ - FileEntry put(DirectoryEntry parent, String name, byte[] content) throws IOException; - - /** - * Removes the specified entry (and if the entry is a directory, all its children). - * - * @param entry the entry to remove. - * @throws UnsupportedOperationException if the repository is read-only. - * @since 1.0 - */ - void remove(Entry entry); } diff --git a/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/ResolverUtils.java b/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/ResolverUtils.java index 7999ac41..6262c087 100644 --- a/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/ResolverUtils.java +++ b/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/ResolverUtils.java @@ -13,6 +13,10 @@ */ public class ResolverUtils { + private ResolverUtils() { + // utility class + } + /** *

Creates a new {@link org.eclipse.aether.artifact.Artifact} based on an {@link Artifact} object.

*

Future deprecation: This method will be replaced with the new Maven 4 diff --git a/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/maven/Artifact.java b/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/maven/Artifact.java index ee471d5f..ff0fe261 100644 --- a/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/maven/Artifact.java +++ b/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/maven/Artifact.java @@ -16,7 +16,6 @@ package org.codehaus.mojo.mrm.api.maven; -import java.io.Serializable; import java.text.MessageFormat; import java.text.SimpleDateFormat; import java.util.Date; @@ -30,14 +29,7 @@ * @serial * @since 1.0 */ -public final class Artifact implements Serializable, Comparable { - - /** - * Ensure consistent serialization. - * - * @since 1.0 - */ - private static final long serialVersionUID = 1L; +public final class Artifact implements Comparable { /** * The groupId of the artifact. @@ -95,7 +87,7 @@ public final class Artifact implements Serializable, Comparable { * * @since 1.0 */ - private transient String name; + private String name; /** * The lazy idempotent cache of the artifact's timestamp version string (which will be equal to the {@link #version} @@ -103,7 +95,7 @@ public final class Artifact implements Serializable, Comparable { * * @since 1.0 */ - private transient String timestampVersion; + private String timestampVersion; /** * Common internal constructor. diff --git a/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/maven/ArtifactStore.java b/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/maven/ArtifactStore.java index 89d9b58c..a4fc4e30 100644 --- a/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/maven/ArtifactStore.java +++ b/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/maven/ArtifactStore.java @@ -18,7 +18,6 @@ import java.io.IOException; import java.io.InputStream; -import java.io.Serializable; import java.util.Set; import org.apache.maven.archetype.catalog.ArchetypeCatalog; @@ -29,7 +28,7 @@ * * @since 1.0 */ -public interface ArtifactStore extends Serializable { +public interface ArtifactStore { /** *

diff --git a/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/maven/BaseArtifactStore.java b/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/maven/BaseArtifactStore.java index 26fa968b..f9ce30d5 100644 --- a/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/maven/BaseArtifactStore.java +++ b/mrm-api/src/main/java/org/codehaus/mojo/mrm/api/maven/BaseArtifactStore.java @@ -21,9 +21,7 @@ public abstract class BaseArtifactStore implements ArtifactStore { */ private static final long serialVersionUID = 1L; - /** - * {@inheritDoc} - */ + @Override public void set(Artifact artifact, InputStream content) throws IOException { throw new UnsupportedOperationException("Read-only artifact store"); } @@ -33,24 +31,18 @@ public void setMetadata(String path, Metadata metadata) throws IOException { throw new UnsupportedOperationException("Read-only artifact store"); } - /** - * {@inheritDoc} - */ + @Override public void setArchetypeCatalog(InputStream content) throws IOException { throw new UnsupportedOperationException("Read-only artifact store"); } - /** - * {@inheritDoc} - */ + @Override public ArchetypeCatalog getArchetypeCatalog() throws IOException, ArchetypeCatalogNotFoundException { throw new ArchetypeCatalogNotFoundException( "Archetype Catalog not available", new UnsupportedOperationException()); } - /** - * {@inheritDoc} - */ + @Override public long getArchetypeCatalogLastModified() throws IOException, ArchetypeCatalogNotFoundException { throw new ArchetypeCatalogNotFoundException( "Archetype Catalog not available", new UnsupportedOperationException()); diff --git a/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/AbstractMRMMojo.java b/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/AbstractMRMMojo.java index b22813ed..4669c558 100644 --- a/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/AbstractMRMMojo.java +++ b/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/AbstractMRMMojo.java @@ -68,7 +68,7 @@ public abstract class AbstractMRMMojo extends AbstractMojo { * Creates a new instance * @param proxyRepo injected proxyRepo */ - public AbstractMRMMojo(ArtifactStoreFactory proxyRepo) { + protected AbstractMRMMojo(ArtifactStoreFactory proxyRepo) { this.proxyRepo = proxyRepo; } @@ -78,6 +78,7 @@ public AbstractMRMMojo(ArtifactStoreFactory proxyRepo) { * @throws MojoExecutionException If there is an exception occuring during the execution of the plugin. * @throws MojoFailureException If there is an exception occuring during the execution of the plugin. */ + @Override public final void execute() throws MojoExecutionException, MojoFailureException { if (skip) { getLog().info("Skipping invocation per configuration." diff --git a/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/AbstractStartMojo.java b/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/AbstractStartMojo.java index 9a2d6fb9..a53de5ce 100644 --- a/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/AbstractStartMojo.java +++ b/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/AbstractStartMojo.java @@ -80,7 +80,7 @@ public abstract class AbstractStartMojo extends AbstractMRMMojo { * @param factoryHelper injected {@link FactoryHelper} instance * @param proxyRepo injected proxyHelper instance */ - public AbstractStartMojo(FactoryHelper factoryHelper, ArtifactStoreFactory proxyRepo) { + protected AbstractStartMojo(FactoryHelper factoryHelper, ArtifactStoreFactory proxyRepo) { super(proxyRepo); this.factoryHelper = factoryHelper; } diff --git a/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/ConsoleScanner.java b/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/ConsoleScanner.java index 2b758867..19f44a38 100644 --- a/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/ConsoleScanner.java +++ b/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/ConsoleScanner.java @@ -42,9 +42,7 @@ public ConsoleScanner() { setDaemon(true); } - /** - * {@inheritDoc} - */ + @Override public void run() { try { synchronized (lock) { diff --git a/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/FileSystemServer.java b/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/FileSystemServer.java index d3fdd4f7..86e2083b 100644 --- a/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/FileSystemServer.java +++ b/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/FileSystemServer.java @@ -109,6 +109,7 @@ public class FileSystemServer { * * @param name The name of the file system server thread. * @param port The port to server on or 0 to pick a random, but available, port. + * @param contextPath The root context path for server * @param fileSystem the file system to serve. * @param debugServer the server debug mode */ @@ -242,9 +243,8 @@ public String getUrl() { * The work to monitor and control the Jetty instance that hosts the file system. */ private final class Worker implements Runnable { - /** - * {@inheritDoc} - */ + + @Override public void run() { try { Logger serverLogger = new ServerLogger(debugServer); diff --git a/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/ProxyRepo.java b/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/ProxyRepo.java index e0aa7edd..7cf1c46a 100644 --- a/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/ProxyRepo.java +++ b/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/ProxyRepo.java @@ -54,9 +54,6 @@ public ProxyRepo(FactoryHelper factoryHelper) { this.factoryHelper = factoryHelper; } - /** - * {@inheritDoc} - */ @Override public ArtifactStore newInstance(MavenSession session, Log log) { return new ProxyArtifactStore( @@ -68,9 +65,7 @@ public void setFactoryHelper(FactoryHelper factoryHelper) { this.factoryHelper = factoryHelper; } - /** - * {@inheritDoc} - */ + @Override public String toString() { return "Proxy (source: this Maven session)"; } diff --git a/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/RunMojo.java b/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/RunMojo.java index be7d445a..78acf6f7 100644 --- a/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/RunMojo.java +++ b/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/RunMojo.java @@ -44,9 +44,7 @@ public RunMojo(FactoryHelper factoryHelper, @Named("proxyRepo") ArtifactStoreFac super(factoryHelper, proxyRepo); } - /** - * {@inheritDoc} - */ + @Override public void doExecute() throws MojoExecutionException, MojoFailureException { if (!session.getSettings().isInteractiveMode()) { throw new MojoExecutionException( @@ -64,7 +62,7 @@ public void doExecute() throws MojoExecutionException, MojoFailureException { getLog().info("Hit ENTER on the console to stop the Mock Repository Manager and continue the build."); consoleScanner.waitForFinished(); } catch (InterruptedException e) { - // ignore + Thread.currentThread().interrupt(); } finally { getLog().info("Stopping Mock Repository Manager " + url); mrm.finish(); @@ -72,7 +70,7 @@ public void doExecute() throws MojoExecutionException, MojoFailureException { mrm.waitForFinished(); getLog().info("Mock Repository Manager " + url + " is stopped."); } catch (InterruptedException e) { - // ignore + Thread.currentThread().interrupt(); } } } diff --git a/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/StartMojo.java b/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/StartMojo.java index 50f76746..29e6cb38 100644 --- a/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/StartMojo.java +++ b/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/StartMojo.java @@ -50,10 +50,7 @@ public StartMojo(FactoryHelper factoryHelper, @Named("proxyRepo") ArtifactStoreF super(factoryHelper, proxyRepo); } - /** - * {@inheritDoc} - */ - @SuppressWarnings({"rawtypes", "unchecked"}) + @Override public void doExecute() throws MojoExecutionException, MojoFailureException { FileSystemServer mrm = createFileSystemServer(createArtifactStore()); getLog().info("Starting Mock Repository Manager"); @@ -64,7 +61,7 @@ public void doExecute() throws MojoExecutionException, MojoFailureException { getLog().info("Setting property '" + propertyName + "' to '" + url + "'."); project.getProperties().setProperty(propertyName, url); } - Map pluginContext = session.getPluginContext(pluginDescriptor, project); + Map pluginContext = session.getPluginContext(pluginDescriptor, project); pluginContext.put(getFileSystemServerKey(getMojoExecution()), mrm); } diff --git a/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/StopMojo.java b/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/StopMojo.java index 1b5b79a9..5819a259 100644 --- a/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/StopMojo.java +++ b/mrm-maven-plugin/src/main/java/org/codehaus/mojo/mrm/plugin/StopMojo.java @@ -43,12 +43,9 @@ public StopMojo(@Named("proxyRepo") ArtifactStoreFactory proxyRepo) { super(proxyRepo); } - /** - * {@inheritDoc} - */ - @SuppressWarnings("rawtypes") + @Override public void doExecute() throws MojoExecutionException, MojoFailureException { - Map pluginContext = session.getPluginContext(pluginDescriptor, project); + Map pluginContext = session.getPluginContext(pluginDescriptor, project); FileSystemServer mrm = (FileSystemServer) pluginContext.get(StartMojo.getFileSystemServerKey(getMojoExecution())); @@ -64,6 +61,7 @@ public void doExecute() throws MojoExecutionException, MojoFailureException { getLog().info("Mock Repository Manager " + url + " is stopped."); pluginContext.remove(FileSystemServer.class.getName()); } catch (InterruptedException e) { + Thread.currentThread().interrupt(); throw new MojoExecutionException(e.getMessage(), e); } } diff --git a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/GenerateOnErrorFileEntry.java b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/GenerateOnErrorFileEntry.java index 11ad64e9..7007dfde 100644 --- a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/GenerateOnErrorFileEntry.java +++ b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/GenerateOnErrorFileEntry.java @@ -31,13 +31,6 @@ */ public class GenerateOnErrorFileEntry extends BaseFileEntry { - /** - * Ensure consistent serialization. - * - * @since 1.0 - */ - private static final long serialVersionUID = 1L; - /** * The entry that we can fall back to if there is an {@link #error}. * @@ -79,9 +72,7 @@ public GenerateOnErrorFileEntry( this.delegateEntry = delegateEntry; } - /** - * {@inheritDoc} - */ + @Override public long getLastModified() throws IOException { if (!error) { try { @@ -95,9 +86,7 @@ public long getLastModified() throws IOException { } } - /** - * {@inheritDoc} - */ + @Override public long getSize() throws IOException { if (!error) { try { @@ -111,9 +100,7 @@ public long getSize() throws IOException { } } - /** - * {@inheritDoc} - */ + @Override public InputStream getInputStream() throws IOException { if (!error) { try { diff --git a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/LinkFileEntry.java b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/LinkFileEntry.java index 64110c6b..bb244cf7 100644 --- a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/LinkFileEntry.java +++ b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/LinkFileEntry.java @@ -31,13 +31,6 @@ */ public class LinkFileEntry extends BaseFileEntry { - /** - * Ensure consistent serialization. - * - * @since 1.0 - */ - private static final long serialVersionUID = 1L; - /** * The backing entry. * @@ -73,23 +66,17 @@ public LinkFileEntry(FileSystem fileSystem, DirectoryEntry parent, String name, this.entry = entry; } - /** - * {@inheritDoc} - */ + @Override public long getLastModified() throws IOException { return entry.getLastModified(); } - /** - * {@inheritDoc} - */ + @Override public long getSize() throws IOException { return entry.getSize(); } - /** - * {@inheritDoc} - */ + @Override public InputStream getInputStream() throws IOException { return entry.getInputStream(); } diff --git a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/RemoteFileEntry.java b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/RemoteFileEntry.java deleted file mode 100644 index f2efb305..00000000 --- a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/RemoteFileEntry.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2011 Stephen Connolly - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.codehaus.mojo.mrm.impl; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; - -import org.codehaus.mojo.mrm.api.BaseFileEntry; -import org.codehaus.mojo.mrm.api.DirectoryEntry; -import org.codehaus.mojo.mrm.api.FileSystem; - -/** - * A {@link org.codehaus.mojo.mrm.api.FileEntry} that is hosted at a remote {@link URL}. - */ -public class RemoteFileEntry extends BaseFileEntry { - - /** - * Ensure consistent serialization. - * - * @since 1.0 - */ - private static final long serialVersionUID = 1L; - - /** - * The {@link URL} of the entry. - */ - private final URL url; - - /** - * Create a new file entry. - * - * @param fileSystem the owning file system. - * @param parent the directory hosting the entry. - * @param name the name of the entry. - * @param url the content of the entry. - */ - public RemoteFileEntry(FileSystem fileSystem, DirectoryEntry parent, String name, URL url) { - super(fileSystem, parent, name); - this.url = url; - } - - /** - * {@inheritDoc} - */ - public long getLastModified() throws IOException { - return url.openConnection().getLastModified(); - } - - /** - * {@inheritDoc} - */ - public long getSize() throws IOException { - return url.openConnection().getContentLength(); - } - - /** - * {@inheritDoc} - */ - public InputStream getInputStream() throws IOException { - return url.openConnection().getInputStream(); - } -} diff --git a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/Utils.java b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/Utils.java index 0e3d8de5..1ebcfff4 100644 --- a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/Utils.java +++ b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/Utils.java @@ -16,20 +16,12 @@ package org.codehaus.mojo.mrm.impl; -import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.nio.charset.StandardCharsets; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; -import org.apache.maven.model.Model; - /** * Utility class. * @@ -45,27 +37,6 @@ private Utils() { throw new IllegalAccessError("Utility class"); } - /** - * Returns an input stream for the specified content. If the content is a byte array, the input stream will be a - * {@link java.io.ByteArrayInputStream} if the content is a File, the input stream will be a - * {@link java.io.FileInputStream} otherwise the content will be converted to a String and then into its UTF-8 - * representation and a {@link java.io.ByteArrayInputStream} returned. - * - * @param content The content. - * @return an input stream of the content. - * @throws java.io.IOException if things go wrong. - * @since 1.0 - */ - public static InputStream asInputStream(Object content) throws IOException { - if (content instanceof byte[]) { - return new ByteArrayInputStream((byte[]) content); - } else if (content instanceof File) { - return new FileInputStream((File) content); - } else { - return new ByteArrayInputStream(content.toString().getBytes(StandardCharsets.UTF_8)); - } - } - /** * Creates an empty jar file. * @@ -113,197 +84,4 @@ public static byte[] newEmptyMavenPluginJarContent(String groupId, String artifa } return bos.toByteArray(); } - - /** - * Converts a GAV coordinate into the base file path and name for all artifacts at that coordinate. - * - * @param groupId the group id. - * @param artifactId the artifact id. - * @param version the version. - * @return the base filepath for artifacts at the specified coordinates. - * @since 1.0 - */ - public static String getGAVPathName(String groupId, String artifactId, String version) { - return getGAVPath(groupId, artifactId, version) + '/' + artifactId + '-' + version; - } - - /** - * Converts a GAV coordinate into the repository path for the directory containing all artifacts at that GAV. - * - * @param groupId the group id. - * @param artifactId the artifact id (may be null to just get the path of the groupId) - * @param version the version (may be null to just get the path of the groupId:artifactId) - * @return the path. - * @since 1.0 - */ - public static String getGAVPath(String groupId, String artifactId, String version) { - return groupId.replace('.', '/') - + (artifactId != null ? ('/' + artifactId + (version != null ? ('/' + version) : "")) : ""); - } - - /** - * Extract the version from an un-interpolated model. - * - * @param model the model. - * @return the version of the project. - * @since 1.0 - */ - public static String getVersion(Model model) { - String version = model.getVersion(); - if (version == null) { - version = model.getParent().getVersion(); - } - return version; - } - - /** - * Extract the artifactId from an un-interpolated model. - * - * @param model the model. - * @return the artifactId of the project. - * @since 1.0 - */ - public static String getArtifactId(Model model) { - String artifactId = model.getArtifactId(); - if (artifactId == null) { - artifactId = model.getParent().getArtifactId(); - } - return artifactId; - } - - /** - * Extract the groupId from an un-interpolated model. - * - * @param model the model. - * @return the groupId of the project. - * @since 1.0 - */ - public static String getGroupId(Model model) { - String groupId = model.getGroupId(); - if (groupId == null) { - groupId = model.getParent().getGroupId(); - } - return groupId; - } - - /** - * Take a path and encode it for use as an URL parameter. - * - * @param path the path. - * @return the path encoded for use as an URL parameter. - * @throws UnsupportedEncodingException if the path cannot be encoded. - * @since 1.0 - */ - public static String urlEncodePath(String path) throws UnsupportedEncodingException { - StringBuilder buf = new StringBuilder(path.length() + 64); - int last = 0; - for (int i = path.indexOf('/'); i != -1; i = path.indexOf('/', last)) { - buf.append(urlEncodePathSegment(path.substring(last, i))); - buf.append(path, i, Math.min(path.length(), i + 1)); - last = i + 1; - } - buf.append(path.substring(last)); - return buf.toString(); - } - - /** - * Take a path segment and encode it for use as an URL parameter. - * - * @param pathSegment the path segment. - * @return the path segment encoded for use as an URL parameter. - * @since 1.0 - */ - public static String urlEncodePathSegment(String pathSegment) { - StringBuilder buf = new StringBuilder(pathSegment.length() + 64); - byte[] chars = pathSegment.getBytes(StandardCharsets.UTF_8); - for (byte aChar : chars) { - switch (aChar) { - case '$': - case '-': - case '_': - case '.': - case '!': - case '*': - case '\'': - case '(': - case ')': - case ',': - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - case 'G': - case 'H': - case 'I': - case 'J': - case 'K': - case 'L': - case 'M': - case 'N': - case 'O': - case 'P': - case 'Q': - case 'R': - case 'S': - case 'T': - case 'U': - case 'V': - case 'W': - case 'X': - case 'Y': - case 'Z': - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - case 'g': - case 'h': - case 'i': - case 'j': - case 'k': - case 'l': - case 'm': - case 'n': - case 'o': - case 'p': - case 'q': - case 'r': - case 's': - case 't': - case 'u': - case 'v': - case 'w': - case 'x': - case 'y': - case 'z': - buf.append((char) aChar); - break; - case ' ': - buf.append('+'); - break; - default: - buf.append('%'); - if ((aChar & 0xf0) == 0) { - buf.append('0'); - } - buf.append(Integer.toHexString(aChar & 0xff)); - break; - } - } - return buf.toString(); - } } diff --git a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/digest/AutoDigestFileSystem.java b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/digest/AutoDigestFileSystem.java index 989511f7..5d977d62 100644 --- a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/digest/AutoDigestFileSystem.java +++ b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/digest/AutoDigestFileSystem.java @@ -84,9 +84,7 @@ public AutoDigestFileSystem(FileSystem backing, DigestFileEntryFactory[] digestF .collect(Collectors.toMap(DigestFileEntryFactory::getType, factory -> factory))); } - /** - * {@inheritDoc} - */ + @Override public Entry[] listEntries(DirectoryEntry directory) { Map result = new TreeMap<>(); Map missing = new HashMap<>(); @@ -120,16 +118,12 @@ public Entry[] listEntries(DirectoryEntry directory) { return result.values().toArray(new Entry[0]); } - /** - * {@inheritDoc} - */ + @Override public long getLastModified(DirectoryEntry entry) throws IOException { return backing.getLastModified(DefaultDirectoryEntry.equivalent(backing, entry)); } - /** - * {@inheritDoc} - */ + @Override public Entry get(String path) { Entry entry = backing.get(path); if (entry == null) { diff --git a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/digest/MD5DigestFileEntry.java b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/digest/MD5DigestFileEntry.java index 4c6ada9f..bd3a430e 100644 --- a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/digest/MD5DigestFileEntry.java +++ b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/digest/MD5DigestFileEntry.java @@ -34,13 +34,6 @@ */ public class MD5DigestFileEntry extends BaseFileEntry { - /** - * Ensure consistent serialization. - * - * @since 1.0 - */ - private static final long serialVersionUID = 1L; - /** * The entry we will calculate the digest of. * @@ -62,23 +55,17 @@ public MD5DigestFileEntry(FileSystem fileSystem, DirectoryEntry parent, FileEntr this.entry = entry; } - /** - * {@inheritDoc} - */ + @Override public long getLastModified() throws IOException { return entry.getLastModified(); } - /** - * {@inheritDoc} - */ + @Override public long getSize() throws IOException { return 32; } - /** - * {@inheritDoc} - */ + @Override public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(getContent()); } @@ -115,16 +102,13 @@ private byte[] getContent() throws IOException { * @since 1.0 */ public static class Factory extends BaseDigestFileEntryFactory { - /** - * {@inheritDoc} - */ + + @Override public String getType() { return ".md5"; } - /** - * {@inheritDoc} - */ + @Override public FileEntry create(FileSystem fileSystem, DirectoryEntry parent, FileEntry entry) { return new MD5DigestFileEntry(fileSystem, parent, entry); } diff --git a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/digest/SHA1DigestFileEntry.java b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/digest/SHA1DigestFileEntry.java index 3ebf47fd..c8004302 100644 --- a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/digest/SHA1DigestFileEntry.java +++ b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/digest/SHA1DigestFileEntry.java @@ -36,13 +36,6 @@ */ public class SHA1DigestFileEntry extends BaseFileEntry { - /** - * Ensure consistent serialization. - * - * @since 1.0 - */ - private static final long serialVersionUID = 1L; - /** * The entry we will calculate the digest of. * @@ -64,23 +57,17 @@ public SHA1DigestFileEntry(FileSystem fileSystem, DirectoryEntry parent, FileEnt this.entry = entry; } - /** - * {@inheritDoc} - */ + @Override public long getLastModified() throws IOException { return entry.getLastModified(); } - /** - * {@inheritDoc} - */ + @Override public long getSize() throws IOException { return 40; } - /** - * {@inheritDoc} - */ + @Override public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(getContent()); } @@ -114,16 +101,13 @@ private byte[] getContent() throws IOException { * @since 1.0 */ public static class Factory extends BaseDigestFileEntryFactory { - /** - * {@inheritDoc} - */ + + @Override public String getType() { return ".sha1"; } - /** - * {@inheritDoc} - */ + @Override public FileEntry create(FileSystem fileSystem, DirectoryEntry parent, FileEntry entry) { return new SHA1DigestFileEntry(fileSystem, parent, entry); } diff --git a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/ArchetypeCatalogFileEntry.java b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/ArchetypeCatalogFileEntry.java index edd79095..fb60f82c 100644 --- a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/ArchetypeCatalogFileEntry.java +++ b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/ArchetypeCatalogFileEntry.java @@ -36,13 +36,6 @@ */ public class ArchetypeCatalogFileEntry extends BaseFileEntry { - /** - * Ensure consistent serialization. - * - * @since 1.0 - */ - private static final long serialVersionUID = 1L; - /** * The backing {@link ArtifactStore}. * @@ -65,9 +58,7 @@ public ArchetypeCatalogFileEntry(FileSystem fileSystem, DirectoryEntry parent, A this.store = store; } - /** - * {@inheritDoc} - */ + @Override public long getSize() throws IOException { try { ArchetypeCatalog metadata = store.getArchetypeCatalog(); @@ -80,9 +71,7 @@ public long getSize() throws IOException { } } - /** - * {@inheritDoc} - */ + @Override public InputStream getInputStream() throws IOException { try { ArchetypeCatalog metadata = store.getArchetypeCatalog(); @@ -95,9 +84,7 @@ public InputStream getInputStream() throws IOException { } } - /** - * {@inheritDoc} - */ + @Override public long getLastModified() throws IOException { try { return store.getArchetypeCatalogLastModified(); diff --git a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/ArtifactFileEntry.java b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/ArtifactFileEntry.java index d698bbc8..69f9ce2e 100644 --- a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/ArtifactFileEntry.java +++ b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/ArtifactFileEntry.java @@ -33,13 +33,6 @@ */ public class ArtifactFileEntry extends BaseFileEntry { - /** - * Ensure consistent serialization. - * - * @since 1.0 - */ - private static final long serialVersionUID = 1L; - /** * The backing {@link Artifact}. * @@ -71,9 +64,7 @@ protected ArtifactFileEntry(FileSystem fileSystem, DirectoryEntry parent, Artifa this.store = store; } - /** - * {@inheritDoc} - */ + @Override public long getSize() throws IOException { try { return store.getSize(artifact); @@ -82,9 +73,7 @@ public long getSize() throws IOException { } } - /** - * {@inheritDoc} - */ + @Override public InputStream getInputStream() throws IOException { try { return store.get(artifact); @@ -93,9 +82,7 @@ public InputStream getInputStream() throws IOException { } } - /** - * {@inheritDoc} - */ + @Override public long getLastModified() throws IOException { try { return store.getLastModified(artifact); @@ -103,14 +90,4 @@ public long getLastModified() throws IOException { throw new IOException("Artifact does not exist", e); } } - - /** - * Gets the backing artifact. - * - * @return the backing artifact. - * @since 1.0 - */ - public Artifact getArtifact() { - return artifact; - } } diff --git a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/CompositeArtifactStore.java b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/CompositeArtifactStore.java index 4a37f4d3..6eafb886 100644 --- a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/CompositeArtifactStore.java +++ b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/CompositeArtifactStore.java @@ -60,9 +60,7 @@ public CompositeArtifactStore(ArtifactStore[] stores) { this.stores = stores; } - /** - * {@inheritDoc} - */ + @Override public Set getGroupIds(String parentGroupId) { Set result = new TreeSet<>(); for (ArtifactStore store : stores) { @@ -75,9 +73,7 @@ public Set getGroupIds(String parentGroupId) { return result; } - /** - * {@inheritDoc} - */ + @Override public Set getArtifactIds(String groupId) { Set result = new TreeSet<>(); for (ArtifactStore store : stores) { @@ -89,9 +85,7 @@ public Set getArtifactIds(String groupId) { return result; } - /** - * {@inheritDoc} - */ + @Override public Set getVersions(String groupId, String artifactId) { Set result = new TreeSet<>(); for (ArtifactStore store : stores) { @@ -103,9 +97,7 @@ public Set getVersions(String groupId, String artifactId) { return result; } - /** - * {@inheritDoc} - */ + @Override public Set getArtifacts(String groupId, String artifactId, String version) { Set result = new TreeSet<>(); for (ArtifactStore store : stores) { @@ -117,9 +109,7 @@ public Set getArtifacts(String groupId, String artifactId, String vers return result; } - /** - * {@inheritDoc} - */ + @Override public long getLastModified(Artifact artifact) throws IOException, ArtifactNotFoundException { for (ArtifactStore store : stores) { try { @@ -131,9 +121,7 @@ public long getLastModified(Artifact artifact) throws IOException, ArtifactNotFo throw new ArtifactNotFoundException(artifact); } - /** - * {@inheritDoc} - */ + @Override public long getSize(Artifact artifact) throws IOException, ArtifactNotFoundException { for (ArtifactStore store : stores) { try { @@ -145,9 +133,7 @@ public long getSize(Artifact artifact) throws IOException, ArtifactNotFoundExcep throw new ArtifactNotFoundException(artifact); } - /** - * {@inheritDoc} - */ + @Override public InputStream get(Artifact artifact) throws IOException, ArtifactNotFoundException { for (ArtifactStore store : stores) { try { @@ -159,16 +145,12 @@ public InputStream get(Artifact artifact) throws IOException, ArtifactNotFoundEx throw new ArtifactNotFoundException(artifact); } - /** - * {@inheritDoc} - */ + @Override public void set(Artifact artifact, InputStream content) throws IOException { throw new IOException("Read-only store"); } - /** - * {@inheritDoc} - */ + @Override public Metadata getMetadata(String path) throws IOException, MetadataNotFoundException { boolean found = false; Metadata result = new Metadata(); @@ -261,9 +243,7 @@ public Metadata getMetadata(String path) throws IOException, MetadataNotFoundExc return result; } - /** - * {@inheritDoc} - */ + @Override public long getMetadataLastModified(String path) throws IOException, MetadataNotFoundException { boolean found = false; long lastModified = 0; @@ -285,6 +265,7 @@ public long getMetadataLastModified(String path) throws IOException, MetadataNot return lastModified; } + @Override public ArchetypeCatalog getArchetypeCatalog() throws IOException, ArchetypeCatalogNotFoundException { boolean found = false; ArchetypeCatalog result = new ArchetypeCatalog(); @@ -303,6 +284,7 @@ public ArchetypeCatalog getArchetypeCatalog() throws IOException, ArchetypeCatal return result; } + @Override public long getArchetypeCatalogLastModified() throws IOException, ArchetypeCatalogNotFoundException { boolean found = false; long lastModified = 0; diff --git a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/DiskArtifactStore.java b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/DiskArtifactStore.java index 846daa5c..3adf41da 100644 --- a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/DiskArtifactStore.java +++ b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/DiskArtifactStore.java @@ -78,9 +78,7 @@ public DiskArtifactStore canWrite(boolean canWrite) { return this; } - /** - * {@inheritDoc} - */ + @Override public Set getGroupIds(String parentGroupId) { File parentDir = StringUtils.isEmpty(parentGroupId) ? root : new File(root, parentGroupId.replace('.', '/')); if (!parentDir.isDirectory()) { @@ -96,9 +94,7 @@ public Set getGroupIds(String parentGroupId) { .collect(Collectors.toSet()); } - /** - * {@inheritDoc} - */ + @Override public Set getArtifactIds(String groupId) { File groupDir = new File(root, groupId.replace('.', '/')); if (!groupDir.isDirectory()) { @@ -116,9 +112,7 @@ public Set getArtifactIds(String groupId) { .collect(Collectors.toSet()); } - /** - * {@inheritDoc} - */ + @Override public Set getVersions(String groupId, String artifactId) { File groupDir = new File(root, groupId.replace('.', '/')); File artifactDir = new File(groupDir, artifactId); @@ -133,9 +127,7 @@ public Set getVersions(String groupId, String artifactId) { return Arrays.stream(dirs).filter(File::isDirectory).map(File::getName).collect(Collectors.toSet()); } - /** - * {@inheritDoc} - */ + @Override public Set getArtifacts(final String groupId, final String artifactId, final String version) { File groupDir = new File(root, groupId.replace('.', '/')); File artifactDir = new File(groupDir, artifactId); @@ -213,9 +205,7 @@ public Artifact get(File file) { return result; } - /** - * {@inheritDoc} - */ + @Override public long getLastModified(Artifact artifact) throws IOException, ArtifactNotFoundException { File file = getFile(artifact); if (!file.isFile()) { @@ -224,9 +214,7 @@ public long getLastModified(Artifact artifact) throws IOException, ArtifactNotFo return file.lastModified(); } - /** - * {@inheritDoc} - */ + @Override public long getSize(Artifact artifact) throws IOException, ArtifactNotFoundException { File file = getFile(artifact); if (!file.isFile()) { @@ -235,9 +223,7 @@ public long getSize(Artifact artifact) throws IOException, ArtifactNotFoundExcep return file.length(); } - /** - * {@inheritDoc} - */ + @Override public InputStream get(Artifact artifact) throws IOException, ArtifactNotFoundException { File file = getFile(artifact); if (!file.isFile()) { @@ -246,9 +232,7 @@ public InputStream get(Artifact artifact) throws IOException, ArtifactNotFoundEx return new FileInputStream(file); } - /** - * {@inheritDoc} - */ + @Override public void set(Artifact artifact, InputStream content) throws IOException { if (!canWrite) { throw new UnsupportedOperationException("Read-only store"); @@ -268,9 +252,7 @@ public void set(Artifact artifact, InputStream content) throws IOException { } } - /** - * {@inheritDoc} - */ + @Override public Metadata getMetadata(String path) throws IOException, MetadataNotFoundException { File file = root; String[] parts = StringUtils.strip(path, "/").split("/"); @@ -308,9 +290,7 @@ public void setMetadata(String path, Metadata metadata) throws IOException { } } - /** - * {@inheritDoc} - */ + @Override public long getMetadataLastModified(String path) throws IOException, MetadataNotFoundException { File file = root; String[] parts = StringUtils.strip(path, "/").split("/"); @@ -334,6 +314,7 @@ public long getMetadataLastModified(String path) throws IOException, MetadataNot return file.lastModified(); } + @Override public ArchetypeCatalog getArchetypeCatalog() throws IOException, ArchetypeCatalogNotFoundException { File file = new File(root, "archetype-catalog.xml"); if (!file.isFile()) { @@ -347,6 +328,7 @@ public ArchetypeCatalog getArchetypeCatalog() throws IOException, ArchetypeCatal } } + @Override public long getArchetypeCatalogLastModified() throws IOException, ArchetypeCatalogNotFoundException { File file = new File(root, "archetype-catalog.xml"); if (!file.isFile()) { diff --git a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/FileSystemArtifactStore.java b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/FileSystemArtifactStore.java index e9263eec..cd77271b 100644 --- a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/FileSystemArtifactStore.java +++ b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/FileSystemArtifactStore.java @@ -69,9 +69,7 @@ public FileSystemArtifactStore(FileSystem backing) { this.backing = backing; } - /** - * {@inheritDoc} - */ + @Override public Set getGroupIds(String parentGroupId) { Entry parentEntry = StringUtils.isEmpty(parentGroupId) ? backing.getRoot() : backing.get(parentGroupId.replace('.', '/')); @@ -86,9 +84,7 @@ public Set getGroupIds(String parentGroupId) { .collect(Collectors.toSet()); } - /** - * {@inheritDoc} - */ + @Override public Set getArtifactIds(String groupId) { Entry parentEntry = backing.get(groupId.replace('.', '/')); if (!(parentEntry instanceof DirectoryEntry)) { @@ -102,9 +98,7 @@ public Set getArtifactIds(String groupId) { .collect(Collectors.toSet()); } - /** - * {@inheritDoc} - */ + @Override public Set getVersions(String groupId, String artifactId) { Entry parentEntry = backing.get(groupId.replace('.', '/') + "/" + artifactId); if (!(parentEntry instanceof DirectoryEntry)) { @@ -118,9 +112,7 @@ public Set getVersions(String groupId, String artifactId) { .collect(Collectors.toSet()); } - /** - * {@inheritDoc} - */ + @Override public Set getArtifacts(final String groupId, final String artifactId, final String version) { Entry parentEntry = backing.get(groupId.replace('.', '/') + "/" + artifactId + "/" + version); if (!(parentEntry instanceof DirectoryEntry)) { @@ -198,9 +190,7 @@ public Artifact get(Entry entry) { return result; } - /** - * {@inheritDoc} - */ + @Override public long getLastModified(Artifact artifact) throws IOException, ArtifactNotFoundException { Entry entry = backing.get(artifact.getGroupId().replace('.', '/') + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/" + artifact.getName()); @@ -210,9 +200,7 @@ public long getLastModified(Artifact artifact) throws IOException, ArtifactNotFo return entry.getLastModified(); } - /** - * {@inheritDoc} - */ + @Override public long getSize(Artifact artifact) throws IOException, ArtifactNotFoundException { Entry entry = backing.get(artifact.getGroupId().replace('.', '/') + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/" + artifact.getName()); @@ -222,9 +210,7 @@ public long getSize(Artifact artifact) throws IOException, ArtifactNotFoundExcep return ((FileEntry) entry).getSize(); } - /** - * {@inheritDoc} - */ + @Override public InputStream get(Artifact artifact) throws IOException, ArtifactNotFoundException { Entry entry = backing.get(artifact.getGroupId().replace('.', '/') + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() + "/" + artifact.getName()); @@ -234,16 +220,12 @@ public InputStream get(Artifact artifact) throws IOException, ArtifactNotFoundEx return ((FileEntry) entry).getInputStream(); } - /** - * {@inheritDoc} - */ + @Override public void set(Artifact artifact, InputStream content) throws IOException { throw new UnsupportedOperationException("Read-only store"); } - /** - * {@inheritDoc} - */ + @Override public Metadata getMetadata(String path) throws IOException, MetadataNotFoundException { Entry entry = backing.get( StringUtils.join(StringUtils.split(StringUtils.strip(path, "/"), "/"), "/") + "/maven-metadata.xml"); @@ -258,9 +240,7 @@ public Metadata getMetadata(String path) throws IOException, MetadataNotFoundExc } } - /** - * {@inheritDoc} - */ + @Override public long getMetadataLastModified(String path) throws IOException, MetadataNotFoundException { Entry entry = backing.get( StringUtils.join(StringUtils.split(StringUtils.strip(path, "/"), "/"), "/") + "/maven-metadata.xml"); @@ -270,19 +250,20 @@ public long getMetadataLastModified(String path) throws IOException, MetadataNot return entry.getLastModified(); } + @Override public ArchetypeCatalog getArchetypeCatalog() throws IOException, ArchetypeCatalogNotFoundException { Entry entry = backing.get("archetype-catalog.xml"); if (!(entry instanceof FileEntry)) { throw new ArchetypeCatalogNotFoundException(); } try (InputStream inputStream = ((FileEntry) entry).getInputStream()) { - return new ArchetypeCatalogXpp3Reader().read(inputStream); } catch (XmlPullParserException e) { throw new IOException(e.getMessage(), e); } } + @Override public long getArchetypeCatalogLastModified() throws IOException, ArchetypeCatalogNotFoundException { Entry entry = backing.get("archetype-catalog.xml"); if (!(entry instanceof FileEntry)) { diff --git a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/MetadataFileEntry.java b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/MetadataFileEntry.java index 440f55c1..6ca16ad9 100644 --- a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/MetadataFileEntry.java +++ b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/MetadataFileEntry.java @@ -36,13 +36,6 @@ */ public class MetadataFileEntry extends BaseFileEntry { - /** - * Ensure consistent serialization. - * - * @since 1.0 - */ - private static final long serialVersionUID = 1L; - /** * The path of the backing {@link Metadata}. * @@ -74,9 +67,7 @@ public MetadataFileEntry(FileSystem fileSystem, DirectoryEntry parent, String pa this.store = store; } - /** - * {@inheritDoc} - */ + @Override public long getSize() throws IOException { try { Metadata metadata = store.getMetadata(path); @@ -89,9 +80,7 @@ public long getSize() throws IOException { } } - /** - * {@inheritDoc} - */ + @Override public InputStream getInputStream() throws IOException { try { Metadata metadata = store.getMetadata(path); @@ -104,9 +93,7 @@ public InputStream getInputStream() throws IOException { } } - /** - * {@inheritDoc} - */ + @Override public long getLastModified() throws IOException { try { return store.getMetadataLastModified(path); diff --git a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/MockArtifactStore.java b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/MockArtifactStore.java index 641e35ae..b604c0ef 100644 --- a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/MockArtifactStore.java +++ b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/impl/maven/MockArtifactStore.java @@ -18,10 +18,10 @@ import java.io.ByteArrayInputStream; import java.io.File; -import java.io.FileInputStream; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Files; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; @@ -195,9 +195,7 @@ public MockArtifactStore(Log log, File root, boolean lazyArchiver) { } } - /** - * {@inheritDoc} - */ + @Override public synchronized Set getGroupIds(String parentGroupId) { TreeSet result = new TreeSet<>(); if (StringUtils.isEmpty(parentGroupId)) { @@ -218,26 +216,20 @@ public synchronized Set getGroupIds(String parentGroupId) { return result; } - /** - * {@inheritDoc} - */ + @Override public synchronized Set getArtifactIds(String groupId) { Map>> artifactMap = contents.get(groupId); return artifactMap == null ? Collections.emptySet() : new TreeSet<>(artifactMap.keySet()); } - /** - * {@inheritDoc} - */ + @Override public synchronized Set getVersions(String groupId, String artifactId) { Map>> artifactMap = contents.get(groupId); Map> versionMap = (artifactMap == null ? null : artifactMap.get(artifactId)); return versionMap == null ? Collections.emptySet() : new TreeSet<>(versionMap.keySet()); } - /** - * {@inheritDoc} - */ + @Override public synchronized Set getArtifacts(String groupId, String artifactId, String version) { Map>> artifactMap = contents.get(groupId); Map> versionMap = (artifactMap == null ? null : artifactMap.get(artifactId)); @@ -246,9 +238,7 @@ public synchronized Set getArtifacts(String groupId, String artifactId return filesMap == null ? Collections.emptySet() : new HashSet<>(filesMap.keySet()); } - /** - * {@inheritDoc} - */ + @Override public synchronized long getLastModified(Artifact artifact) throws IOException, ArtifactNotFoundException { Map>> artifactMap = contents.get(artifact.getGroupId()); Map> versionMap = @@ -275,9 +265,7 @@ public synchronized long getLastModified(Artifact artifact) throws IOException, return content.getLastModified(); } - /** - * {@inheritDoc} - */ + @Override public synchronized long getSize(Artifact artifact) throws IOException, ArtifactNotFoundException { Map>> artifactMap = contents.get(artifact.getGroupId()); Map> versionMap = @@ -304,9 +292,7 @@ public synchronized long getSize(Artifact artifact) throws IOException, Artifact return content.getLength(); } - /** - * {@inheritDoc} - */ + @Override public synchronized InputStream get(Artifact artifact) throws IOException, ArtifactNotFoundException { Map>> artifactMap = contents.get(artifact.getGroupId()); Map> versionMap = @@ -333,9 +319,7 @@ public synchronized InputStream get(Artifact artifact) throws IOException, Artif return content.getInputStream(); } - /** - * {@inheritDoc} - */ + @Override public synchronized void set(Artifact artifact, InputStream content) throws IOException { try { set(artifact, new BytesContent(IOUtils.toByteArray(content))); @@ -360,9 +344,7 @@ private synchronized void set(Artifact artifact, Content content) { filesMap.put(artifact, content); } - /** - * {@inheritDoc} - */ + @Override @SuppressWarnings("checkstyle:MethodLength") public synchronized Metadata getMetadata(String path) throws IOException, MetadataNotFoundException { Metadata metadata = new Metadata(); @@ -528,9 +510,7 @@ public synchronized Metadata getMetadata(String path) throws IOException, Metada return metadata; } - /** - * {@inheritDoc} - */ + @Override public synchronized long getMetadataLastModified(String path) throws IOException, MetadataNotFoundException { boolean haveResult = false; long result = 0; @@ -583,6 +563,7 @@ public synchronized long getMetadataLastModified(String path) throws IOException throw new MetadataNotFoundException(path); } + @Override public ArchetypeCatalog getArchetypeCatalog() throws IOException, ArchetypeCatalogNotFoundException { if (archetypeCatalog != null) { ArchetypeCatalogXpp3Reader reader = new ArchetypeCatalogXpp3Reader(); @@ -602,6 +583,7 @@ public ArchetypeCatalog getArchetypeCatalog() throws IOException, ArchetypeCatal throw new ArchetypeCatalogNotFoundException(); } + @Override public long getArchetypeCatalogLastModified() throws ArchetypeCatalogNotFoundException { if (archetypeCatalog != null) { return archetypeCatalog.getLastModified(); @@ -711,23 +693,17 @@ private BytesContent(byte[] bytes) { this.bytes = bytes; } - /** - * {@inheritDoc} - */ + @Override public long getLastModified() { return lastModified; } - /** - * {@inheritDoc} - */ + @Override public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(bytes); } - /** - * {@inheritDoc} - */ + @Override public long getLength() { return bytes.length; } @@ -757,23 +733,17 @@ private FileContent(File file) { this.file = file; } - /** - * {@inheritDoc} - */ + @Override public long getLastModified() { return file.lastModified(); } - /** - * {@inheritDoc} - */ + @Override public InputStream getInputStream() throws IOException { - return new FileInputStream(file); + return Files.newInputStream(file.toPath()); } - /** - * {@inheritDoc} - */ + @Override public long getLength() { return file.length(); } @@ -809,6 +779,7 @@ private void createArchive() { } } + @Override public long getLastModified() { if (archivedFile == null) { createArchive(); @@ -816,13 +787,15 @@ public long getLastModified() { return archivedFile.lastModified(); } + @Override public InputStream getInputStream() throws IOException { if (archivedFile == null) { createArchive(); } - return new FileInputStream(archivedFile); + return Files.newInputStream(archivedFile.toPath()); } + @Override public long getLength() { if (archivedFile == null) { createArchive(); diff --git a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/servlet/FileSystemServlet.java b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/servlet/FileSystemServlet.java index 9709c004..97242469 100644 --- a/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/servlet/FileSystemServlet.java +++ b/mrm-servlet/src/main/java/org/codehaus/mojo/mrm/servlet/FileSystemServlet.java @@ -23,14 +23,11 @@ import java.io.IOException; import java.io.InputStream; -import java.io.PrintWriter; import java.net.HttpURLConnection; -import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; -import java.util.Date; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; @@ -39,7 +36,6 @@ import org.codehaus.mojo.mrm.api.Entry; import org.codehaus.mojo.mrm.api.FileEntry; import org.codehaus.mojo.mrm.api.FileSystem; -import org.codehaus.mojo.mrm.impl.Utils; /** * Servlet that serves a {@link FileSystem}. @@ -48,20 +44,6 @@ */ public class FileSystemServlet extends HttpServlet { - /** - * Width of the name column in the HTML view. - * - * @since 1.0 - */ - private static final int NAME_COL_WIDTH = 50; - - /** - * Width of the size column in the HTML view. - * - * @since 1.0 - */ - private static final int SIZE_COL_WIDTH = 20; - /** * The file system that we are serving. * @@ -82,15 +64,11 @@ public FileSystemServlet(FileSystem fileSystem) { /** * {@inheritDoc} */ - @SuppressWarnings("checkstyle:MethodLength") + @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { String path = req.getPathInfo(); - String context; if (path == null) { path = req.getServletPath(); - context = req.getContextPath(); - } else { - context = req.getContextPath() + req.getServletPath(); } Entry entry = fileSystem.get(path); @@ -112,75 +90,6 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO IOUtils.copy(source, resp.getOutputStream()); } return; - } else if (entry instanceof DirectoryEntry) { - if (!path.endsWith("/")) { - resp.sendRedirect(entry.getName() + "/"); - return; - } - DirectoryEntry dirEntry = (DirectoryEntry) entry; - Entry[] entries = fileSystem.listEntries(dirEntry); - resp.setContentType("text/html"); - PrintWriter w = resp.getWriter(); - w.println(""); - w.println(" "); - w.println(" Index of " + context + path + ""); - w.println(" "); - w.println(""); - w.println(""); - w.println("

Index of " + context + path + "

"); - w.println("
"); - w.write("
");
-
-            if (dirEntry.getParent() != null) {
-                w.println("../");
-            }
-            SimpleDateFormat format = new SimpleDateFormat("dd-MMM-yyyy hh:mm");
-            if (entries != null) {
-                for (int i = 0; i < entries.length; i++) {
-                    final String childName = entries[i].getName();
-                    boolean directory = entries[i] instanceof DirectoryEntry;
-                    if (directory) {
-                        String dirName = childName + "/";
-                        w.write("" + formatName(dirName)
-                                + "" + StringUtils.repeat(" ", Math.max(0, NAME_COL_WIDTH - dirName.length())));
-                    } else {
-                        w.write("" + formatName(childName)
-                                + "" + StringUtils.repeat(" ", Math.max(0, NAME_COL_WIDTH - childName.length())));
-                    }
-
-                    long timestamp = 0;
-                    try {
-                        timestamp = entries[i].getLastModified();
-                    } catch (IOException e) {
-                        // ignore
-                    }
-
-                    w.write(" ");
-                    w.write(format.format(timestamp != -1 ? new Date(timestamp) : new Date()));
-                    if (directory) {
-                        w.println(StringUtils.leftPad("-", SIZE_COL_WIDTH));
-                    } else if (entries[i] instanceof FileEntry) {
-                        FileEntry fileEntry = (FileEntry) entries[i];
-                        try {
-                            long size = fileEntry.getSize();
-                            if (size >= 0) {
-                                w.println(StringUtils.leftPad(Long.toString(size), SIZE_COL_WIDTH));
-                            } else {
-                                w.println(StringUtils.leftPad("-", SIZE_COL_WIDTH));
-                            }
-                        } catch (IOException e) {
-                            w.println(StringUtils.leftPad("-", SIZE_COL_WIDTH));
-                        }
-                    } else {
-                        w.println(StringUtils.leftPad("-", SIZE_COL_WIDTH));
-                    }
-                }
-            }
-            w.write("
"); - w.println("
"); - w.println(""); - w.println(""); - return; } resp.sendError(HttpURLConnection.HTTP_NOT_FOUND); @@ -191,12 +100,8 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO */ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String path = req.getPathInfo(); - String context; if (path == null) { path = req.getServletPath(); - context = req.getContextPath(); - } else { - context = req.getContextPath() + req.getServletPath(); } if (path.endsWith("/")) { resp.sendError(HttpURLConnection.HTTP_BAD_METHOD); @@ -228,42 +133,4 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws Se resp.sendError(HttpURLConnection.HTTP_BAD_METHOD); } - - /** - * {@inheritDoc} - */ - protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - String path = req.getPathInfo(); - String context; - if (path == null) { - path = req.getServletPath(); - context = req.getContextPath(); - } else { - context = req.getContextPath() + req.getServletPath(); - } - Entry entry = fileSystem.get(path); - if (entry == null) { - resp.setStatus(HttpURLConnection.HTTP_OK); - return; - } - try { - fileSystem.remove(entry); - resp.setStatus(HttpURLConnection.HTTP_OK); - } catch (UnsupportedOperationException e) { - resp.sendError(HttpURLConnection.HTTP_BAD_METHOD); - } - } - - /** - * Formats a name for the fixed width layout of the html index. - * - * @param name the name. - * @return the name or the name shortened to 50 characters. - */ - private static String formatName(String name) { - if (name.length() < NAME_COL_WIDTH) { - return name; - } - return name.substring(0, NAME_COL_WIDTH - 1) + ">"; - } }