Skip to content

Commit

Permalink
Jetty 12.0.x refactor common maven plugin classes (#11651)
Browse files Browse the repository at this point in the history
* Issue #11514 - Cleanup `jetty.webapp.addServerClasses` property behavior for ee10/ee9/ee8

* Merging patterns (default -> env -> config)
* Moved ClassMatcher to util
* System Server Classes
* Renaming to Hidden/Protected
* Updated for loss of dump.war
* Update jetty-core/jetty-ee/src/main/java/org/eclipse/jetty/ee/WebappClassLoading.java
* fixed OSGi tests
* Ensure default hidden server and system classes.
* Fixed ee9 OSGi to load jetty-ee
* Adding more deprecations
* Changing XML demos/tests to use new getter names
* rollback xml changes in ee9/ee8
* Fix ee8 maven plugin
* Make jetty-maven dependency optional in ee9 to match ee10

---------

Co-authored-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
Co-authored-by: gregw <gregw@webtide.com>
  • Loading branch information
3 people committed Apr 26, 2024
1 parent 7da9056 commit e9c71be
Show file tree
Hide file tree
Showing 115 changed files with 1,554 additions and 4,799 deletions.
122 changes: 122 additions & 0 deletions jetty-core/jetty-maven/pom.xml
@@ -0,0 +1,122 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-core</artifactId>
<version>12.0.9-SNAPSHOT</version>
</parent>
<artifactId>jetty-maven</artifactId>
<name>Core :: Maven</name>
<properties>
<bundle-symbolic-name>${project.groupId}.maven</bundle-symbolic-name>
<spotbugs.onlyAnalyze>org.eclipse.jetty.maven.*</spotbugs.onlyAnalyze>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-tools-api</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-api-xml</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-xml-impl</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-xml-meta</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jmx</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-security</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-xml</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>@{argLine} ${jetty.surefire.argLine}
--add-reads org.eclipse.jetty.maven=org.eclipse.jetty.logging</argLine>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,208 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//

package org.eclipse.jetty.maven;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;

import org.eclipse.jetty.util.Scanner;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* JettyForkedChild
*
* This is the class that is executed when the jetty maven plugin
* forks a process when DeploymentMode=FORKED.
*/
public abstract class AbstractForkedChild extends ContainerLifeCycle
{
private static final Logger LOG = LoggerFactory.getLogger(AbstractForkedChild.class);

protected AbstractJettyEmbedder jetty;
protected File tokenFile; // TODO: convert to Path
protected Scanner scanner;
protected File webAppPropsFile; // TODO: convert to Path
protected int scanInterval;

/**
* @param args arguments that were passed to main
* @throws Exception if unable to configure
*/
public AbstractForkedChild(String[] args)
throws Exception
{
jetty = newJettyEmbedder();
configure(args);
}

public AbstractJettyEmbedder getJettyEmbedder()
{
return jetty;
}

protected abstract AbstractJettyEmbedder newJettyEmbedder();

/**
* Based on the args passed to the program, configure jetty.
*
* @param args args that were passed to the program.
* @throws Exception if unable to load webprops
*/
public void configure(String[] args)
throws Exception
{
Map<String, String> jettyProperties = new HashMap<>();

for (int i = 0; i < args.length; i++)
{
//--stop-port
if ("--stop-port".equals(args[i]))
{
jetty.setStopPort(Integer.parseInt(args[++i]));
continue;
}

//--stop-key
if ("--stop-key".equals(args[i]))
{
jetty.setStopKey(args[++i]);
continue;
}

//--jettyXml
if ("--jetty-xml".equals(args[i]))
{
List<File> jettyXmls = new ArrayList<>();
String[] names = StringUtil.csvSplit(args[++i]);
for (int j = 0; names != null && j < names.length; j++)
{
jettyXmls.add(new File(names[j].trim()));
}
jetty.setJettyXmlFiles(jettyXmls);
continue;
}
//--webprops
if ("--webprops".equals(args[i]))
{
webAppPropsFile = new File(args[++i].trim());
jetty.setWebAppProperties(loadWebAppProps());
continue;
}

//--token
if ("--token".equals(args[i]))
{
tokenFile = new File(args[++i].trim());
continue;
}

if ("--scanInterval".equals(args[i]))
{
scanInterval = Integer.parseInt(args[++i].trim());
scanner = new Scanner();
scanner.setReportExistingFilesOnStartup(false);
scanner.setScanInterval(scanInterval);
scanner.addListener(new Scanner.BulkListener()
{
public void filesChanged(Set<String> changes)
{
if (!Objects.isNull(scanner))
{
try
{
scanner.stop();
jetty.redeployWebApp(loadWebAppProps());
scanner.start();
}
catch (Exception e)
{
LOG.error("Error reconfiguring/restarting webapp after change in watched files", e);
}
}
}
});

if (!Objects.isNull(webAppPropsFile))
scanner.addFile(webAppPropsFile.toPath());
continue;
}

//assume everything else is a jetty property to be passed in
String[] tmp = args[i].trim().split("=");
if (tmp.length == 2)
{
jettyProperties.put(tmp[0], tmp[1]);
}
}

jetty.setJettyProperties(jettyProperties);
jetty.setExitVm(true);
}

/**
* Load properties from a file describing the webapp if one is
* present.
*
* @return file contents as properties
* @throws FileNotFoundException if there is a file not found problem
* @throws IOException if there is an IO problem
*/
protected Properties loadWebAppProps() throws FileNotFoundException, IOException
{
Properties props = new Properties();
if (Objects.nonNull(webAppPropsFile))
props.load(new FileInputStream(webAppPropsFile));
return props;
}

/**
* Start a jetty instance and webapp. This thread will
* wait until jetty exits.
*/
public void doStart()
throws Exception
{
super.doStart();

//Start the embedded jetty instance
jetty.start();

//touch file to signify start of jetty
Path tokenPath = tokenFile.toPath();
Files.createFile(tokenPath);

//Start a watcher on a file that will change if the
//webapp is regenerated; stop the webapp, apply the
//properties and restart it.
if (scanner != null)
scanner.start();

//wait for jetty to finish
jetty.join();
}
}
Expand Up @@ -11,7 +11,7 @@
// ========================================================================
//

package org.eclipse.jetty.ee9.maven.plugin;
package org.eclipse.jetty.maven;

import java.io.File;
import java.util.List;
Expand Down

0 comments on commit e9c71be

Please sign in to comment.