Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove of downloading predefined settings.xml by run mojo #174

Merged
merged 1 commit into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,9 @@ protected FileSystemServer createFileSystemServer(ArtifactStore artifactStore) {
Math.max(0, Math.min(port, 65535)),
basePath,
new AutoDigestFileSystem(new ArtifactStoreFileSystem(artifactStore)),
getSettingsServletPath(),
debugServer);
}

/**
* When set, this points to the location from where the settings file can be downloaded.
*
* @return the servlet path to the settings file of {@code null}
*/
protected String getSettingsServletPath() {
return null;
}

/**
* Creates an artifact store from the {@link #repositories} configuration.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
* limitations under the License.
*/

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.mojo.mrm.api.FileSystem;
import org.codehaus.mojo.mrm.servlet.FileSystemServlet;
Expand Down Expand Up @@ -102,11 +99,6 @@ public class FileSystemServer {
*/
private final String contextPath;

/**
* The path to settingsFile containing the configuration to connect to this repository manager.
*/
private final String settingsServletPath;

/**
* Indicate debug level by Jetty server
*/
Expand All @@ -120,18 +112,11 @@ public class FileSystemServer {
* @param fileSystem the file system to serve.
* @param debugServer the server debug mode
*/
public FileSystemServer(
String name,
int port,
String contextPath,
FileSystem fileSystem,
String settingsServletPath,
boolean debugServer) {
public FileSystemServer(String name, int port, String contextPath, FileSystem fileSystem, boolean debugServer) {
this.name = name;
this.fileSystem = fileSystem;
this.requestedPort = port;
this.contextPath = sanitizeContextPath(contextPath);
this.settingsServletPath = settingsServletPath;
this.debugServer = debugServer;
}

Expand Down Expand Up @@ -253,17 +238,6 @@ public String getUrl() {
return "http://localhost:" + getPort() + (contextPath.equals("/") ? "" : contextPath);
}

/**
* Same as {@link #getUrl()}, but now for remote users
*
* @return the scheme + raw IP address + port + contextPath
* @throws UnknownHostException if the local host name could not be resolved into an address.
*/
public String getRemoteUrl() throws UnknownHostException {
return "http://" + InetAddress.getLocalHost().getHostAddress() + ":" + getPort()
+ (contextPath.equals("/") ? "" : contextPath);
}

/**
* The work to monitor and control the Jetty instance that hosts the file system.
*/
Expand All @@ -282,7 +256,7 @@ public void run() {
try {
ServletContextHandler context = new ServletContextHandler();
context.setContextPath(contextPath);
context.addServlet(new ServletHolder(new FileSystemServlet(fileSystem, settingsServletPath)), "/*");
context.addServlet(new ServletHolder(new FileSystemServlet(fileSystem)), "/*");
server.setHandler(context);
server.start();
synchronized (lock) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@
import javax.inject.Inject;
import javax.inject.Named;

import java.net.UnknownHostException;

import org.apache.maven.plugin.MojoExecutionException;
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.FileUtils;
import org.codehaus.plexus.util.StringUtils;

/**
* This goal is used in-situ on a Maven project to allow integration tests based on the Maven Invoker to use a custom
Expand All @@ -38,11 +33,6 @@
*/
@Mojo(name = "run", requiresProject = false, requiresDirectInvocation = true, threadSafe = true)
public class RunMojo extends AbstractStartMojo {
/**
* ServletPath for the settings.xml, so it can be downloaded.
*/
@Parameter(property = "mrm.settingsServletPath", defaultValue = "settings-mrm.xml")
private String settingsServletPath;

/**
* Creates a new instance
Expand All @@ -69,20 +59,6 @@ public void doExecute() throws MojoExecutionException, MojoFailureException {
String url = mrm.getUrl();
try {
getLog().info("Mock Repository Manager " + url + " is started.");
if (StringUtils.isNotEmpty(settingsServletPath)) {
String downloadUrl;
try {
downloadUrl = mrm.getRemoteUrl();
} catch (UnknownHostException e) {
downloadUrl = mrm.getUrl();
}

String settings = FileUtils.filename(settingsServletPath);

getLog().info("To share this repository manager, let users download " + downloadUrl + "/"
+ settingsServletPath);
getLog().info("Maven should be started as 'mvn --settings " + settings + " [phase|goal]'");
}
ConsoleScanner consoleScanner = new ConsoleScanner();
consoleScanner.start();
getLog().info("Hit ENTER on the console to stop the Mock Repository Manager and continue the build.");
Expand All @@ -100,12 +76,4 @@ public void doExecute() throws MojoExecutionException, MojoFailureException {
}
}
}

/**
* {@inheritDoc}
*/
@Override
protected String getSettingsServletPath() {
return settingsServletPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,13 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Reader;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.Date;

import org.apache.commons.io.IOUtils;
Expand All @@ -45,8 +40,6 @@
import org.codehaus.mojo.mrm.api.FileEntry;
import org.codehaus.mojo.mrm.api.FileSystem;
import org.codehaus.mojo.mrm.impl.Utils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.InterpolationFilterReader;

/**
* Servlet that serves a {@link FileSystem}.
Expand Down Expand Up @@ -76,27 +69,21 @@ public class FileSystemServlet extends HttpServlet {
*/
private final FileSystem fileSystem;

/**
* @since 1.0
*/
private String settingsServletPath;

/**
* Constructor that takes a specific file system instance.
*
* @param fileSystem the file systen to serve.
* @since 1.0
*/
public FileSystemServlet(FileSystem fileSystem, String settingsServletPath) {
public FileSystemServlet(FileSystem fileSystem) {
this.fileSystem = fileSystem;
this.settingsServletPath = settingsServletPath;
}

/**
* {@inheritDoc}
*/
@SuppressWarnings("checkstyle:MethodLength")
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
String path = req.getPathInfo();
String context;
if (path == null) {
Expand All @@ -106,27 +93,6 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
context = req.getContextPath() + req.getServletPath();
}

if (path.equals("/" + settingsServletPath)) {
resp.setContentType("text/xml");
PrintWriter w = resp.getWriter();

String hostAddress;
try {
hostAddress = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
hostAddress = req.getServerName();
}

String repositoryProxyUrl = req.getScheme() + "://" + hostAddress + ":" + req.getServerPort();

try (Reader in = new InputStreamReader(FileSystemServlet.class.getResourceAsStream("/settings-mrm.xml"));
Reader settingsReader = new InterpolationFilterReader(
in, Collections.singletonMap("repository.proxy.url", repositoryProxyUrl), "@", "@")) {
IOUtil.copy(settingsReader, w);
}
return;
}

Entry entry = fileSystem.get(path);
if (entry instanceof FileEntry) {
FileEntry fileEntry = (FileEntry) entry;
Expand Down
69 changes: 0 additions & 69 deletions mrm-servlet/src/main/resources/settings-mrm.xml

This file was deleted.