Skip to content

Commit

Permalink
[MDEPLOY-313] Update to parent 41, cleanup
Browse files Browse the repository at this point in the history
In general perform a cleanup of plugin, apply updates,
where needed. The plugin now builds against latest 3.9.x
and minimum is lifted to 3.6.3.

---

https://issues.apache.org/jira/browse/MDEPLOY-313
  • Loading branch information
cstamas committed Jan 12, 2024
1 parent 29f3c81 commit 6d136a7
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 125 deletions.
58 changes: 37 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ under the License.
<parent>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugins</artifactId>
<version>39</version>
<version>41</version>
<relativePath />
</parent>

Expand All @@ -43,7 +43,7 @@ under the License.
</contributors>

<prerequisites>
<maven>${mavenVersion}</maven>
<maven>3.6.3</maven>
</prerequisites>

<scm>
Expand All @@ -69,23 +69,23 @@ under the License.

<properties>
<javaVersion>8</javaVersion>
<mavenVersion>3.2.5</mavenVersion>
<mavenVersion>3.9.6</mavenVersion>
<!-- Keep in sync with resolver used in maven above -->
<slf4jVersion>1.7.5</slf4jVersion>
<slf4jVersion>1.7.36</slf4jVersion>
<!-- Keep in sync with resolver used in maven above -->
<resolverVersion>1.0.0.v20140518</resolverVersion>
<resolverVersion>1.9.18</resolverVersion>

<!-- plugins version used in IT tests -->
<mavenAntrunPluginVersion>3.1.0</mavenAntrunPluginVersion>
<mavenCompilerPluginVersion>3.10.1</mavenCompilerPluginVersion>
<mavenEnforcerPluginVersion>3.1.0</mavenEnforcerPluginVersion>
<mavenInstallPluginVersion>3.1.0</mavenInstallPluginVersion>
<mavenCompilerPluginVersion>3.12.1</mavenCompilerPluginVersion>
<mavenEnforcerPluginVersion>3.4.1</mavenEnforcerPluginVersion>
<mavenInstallPluginVersion>3.1.1</mavenInstallPluginVersion>
<mavenJarPluginVersion>3.3.0</mavenJarPluginVersion>
<mavenJavadocPluginVersion>3.4.1</mavenJavadocPluginVersion>
<mavenPluginToolsVersion>${maven.plugin.tools.version}</mavenPluginToolsVersion>
<mavenResourcesPluginVersion>3.3.0</mavenResourcesPluginVersion>
<mavenSourcePluginVersion>3.2.1</mavenSourcePluginVersion>
<mavenSurefirePluginVersion>${surefire.version}</mavenSurefirePluginVersion>
<mavenSurefirePluginVersion>3.2.5</mavenSurefirePluginVersion>
<mavenWarPluginVersion>3.3.2</mavenWarPluginVersion>

<project.build.outputTimestamp>2023-03-21T14:38:01Z</project.build.outputTimestamp>
Expand Down Expand Up @@ -128,14 +128,18 @@ under the License.
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-api</artifactId>
<version>${resolverVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-util</artifactId>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-util</artifactId>
<version>${resolverVersion}</version>
<!-- To work in Maven versions older than 3.9.0 -->
<scope>compile</scope>
Expand Down Expand Up @@ -164,25 +168,25 @@ under the License.
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-aether-provider</artifactId>
<artifactId>maven-resolver-provider</artifactId>
<version>${mavenVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-connector-basic</artifactId>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-connector-basic</artifactId>
<version>${resolverVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-file</artifactId>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-file</artifactId>
<version>${resolverVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-transport-http</artifactId>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-transport-http</artifactId>
<version>${resolverVersion}</version>
<scope>test</scope>
</dependency>
Expand All @@ -204,9 +208,21 @@ under the License.
<version>${slf4jVersion}</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<proc>none</proc>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>run-its</id>
Expand Down
4 changes: 2 additions & 2 deletions src/it/MDEPLOY-178_deployfile-with-embedded-pom/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ File buildLog = new File( basedir, 'build.log' )
assert buildLog.exists()
assert buildLog.text.contains( "[DEBUG] Using META-INF/maven/org.apache.maven.plugins.deploy.its/mdeploy178/pom.xml as pomFile" )

def pomProject = new XmlSlurper().parse( deployedPom )
assert "https://issues.apache.org/jira/browse/MDEPLOY-178".equals( pomProject.url.text() )
def pomProject = new groovy.xml.XmlParser().parse( deployedPom )
assert "https://issues.apache.org/jira/browse/MDEPLOY-178".equals( pomProject.get("url").text() )
27 changes: 7 additions & 20 deletions src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.WriterFactory;
import org.codehaus.plexus.util.xml.ReaderFactory;
import org.codehaus.plexus.util.xml.WriterFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
Expand Down Expand Up @@ -429,21 +429,14 @@ private void processModel(Model model) {
* @throws MojoExecutionException If the file doesn't exist or cannot be read.
*/
Model readModel(File pomFile) throws MojoExecutionException {
Reader reader = null;
try {
reader = ReaderFactory.newXmlReader(pomFile);
final Model model = new MavenXpp3Reader().read(reader);
reader.close();
reader = null;
return model;
try (Reader reader = ReaderFactory.newXmlReader(pomFile)) {
return new MavenXpp3Reader().read(reader);
} catch (FileNotFoundException e) {
throw new MojoExecutionException("POM not found " + pomFile, e);
} catch (IOException e) {
throw new MojoExecutionException("Error reading POM " + pomFile, e);
} catch (XmlPullParserException e) {
throw new MojoExecutionException("Error parsing POM " + pomFile, e);
} finally {
IOUtil.close(reader);
}
}

Expand All @@ -456,23 +449,17 @@ Model readModel(File pomFile) throws MojoExecutionException {
private File generatePomFile() throws MojoExecutionException {
Model model = generateModel();

Writer fw = null;
try {
File tempFile = File.createTempFile("mvndeploy", ".pom");
tempFile.deleteOnExit();

fw = WriterFactory.newXmlWriter(tempFile);

new MavenXpp3Writer().write(fw, model);

fw.close();
fw = null;
try (Writer fw = WriterFactory.newXmlWriter(tempFile)) {
new MavenXpp3Writer().write(fw, model);
}

return tempFile;
} catch (IOException e) {
throw new MojoExecutionException("Error writing temporary pom file: " + e.getMessage(), e);
} finally {
IOUtil.close(fw);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.project.ProjectBuildingRequest;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.internal.impl.DefaultLocalPathComposer;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.repository.LocalRepository;
import org.mockito.InjectMocks;
Expand Down Expand Up @@ -86,8 +87,9 @@ public void testBasicDeployFile() throws Exception {
when(buildingRequest.getRepositoryMerging()).thenReturn(ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT);
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
repositorySession.setLocalRepositoryManager(
new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer())
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
when(session.getRepositorySession()).thenReturn(repositorySession);

Expand Down Expand Up @@ -194,8 +196,9 @@ public void testDeployIfClassifierIsSet() throws Exception {
when(buildingRequest.getRepositoryMerging()).thenReturn(ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT);
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
repositorySession.setLocalRepositoryManager(
new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer())
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
when(session.getRepositorySession()).thenReturn(repositorySession);

Expand Down Expand Up @@ -248,8 +251,9 @@ public void testDeployIfArtifactIsNotJar() throws Exception {
when(buildingRequest.getRepositoryMerging()).thenReturn(ProjectBuildingRequest.RepositoryMerging.POM_DOMINANT);
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
repositorySession.setLocalRepositoryManager(
new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer())
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
when(session.getRepositorySession()).thenReturn(repositorySession);

Expand Down
90 changes: 14 additions & 76 deletions src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.maven.execution.MavenSession;
Expand All @@ -37,11 +36,10 @@
import org.apache.maven.project.ProjectBuildingRequest;
import org.codehaus.plexus.util.FileUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.internal.impl.DefaultLocalPathComposer;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.RemoteRepository;
import org.junit.Ignore;
import org.mockito.InjectMocks;
import org.mockito.MockitoAnnotations;

Expand Down Expand Up @@ -75,10 +73,11 @@ public void setUp() throws Exception {

session = mock(MavenSession.class);
when(session.getPluginContext(any(PluginDescriptor.class), any(MavenProject.class)))
.thenReturn(new ConcurrentHashMap<String, Object>());
.thenReturn(new ConcurrentHashMap<>());
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
repositorySession.setLocalRepositoryManager(
new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer())
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
when(session.getRepositorySession()).thenReturn(repositorySession);

remoteRepo = new File(REMOTE_REPO);
Expand Down Expand Up @@ -124,8 +123,9 @@ public void testBasicDeploy() throws Exception {
ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
repositorySession.setLocalRepositoryManager(
new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer())
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
when(session.getRepositorySession()).thenReturn(repositorySession);

Expand Down Expand Up @@ -300,8 +300,9 @@ public void testBasicDeployWithPackagingAsPom() throws Exception {
ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
repositorySession.setLocalRepositoryManager(
new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer())
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
when(session.getRepositorySession()).thenReturn(repositorySession);

Expand Down Expand Up @@ -413,8 +414,9 @@ public void testDeployWithAttachedArtifacts() throws Exception {
ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory()
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
repositorySession.setLocalRepositoryManager(
new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer())
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
when(session.getRepositorySession()).thenReturn(repositorySession);

Expand Down Expand Up @@ -490,70 +492,6 @@ public void testDeployWithAttachedArtifacts() throws Exception {
assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles));
}

@Ignore("SCP is not part of Maven3 distribution. Aether handles transport extensions.")
public void _testBasicDeployWithScpAsProtocol() throws Exception {
String originalUserHome = System.getProperty("user.home");

// FIX THE DAMN user.home BEFORE YOU DELETE IT!!!
File altHome = new File(getBasedir(), "target/ssh-user-home");
altHome.mkdirs();

System.out.println("Testing user.home value for .ssh dir: " + altHome.getCanonicalPath());

Properties props = System.getProperties();
props.setProperty("user.home", altHome.getCanonicalPath());

System.setProperties(props);

File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-scp/plugin-config.xml");

mojo = (DeployMojo) lookupMojo("deploy", testPom);

assertNotNull(mojo);

RepositorySystem repositorySystem = mock(RepositorySystem.class);

setVariableValueToObject(mojo, "repositorySystem", repositorySystem);

File file = new File(
getBasedir(),
"target/test-classes/unit/basic-deploy-scp/target/" + "deploy-test-file-1.0-SNAPSHOT.jar");

assertTrue(file.exists());

MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");

setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));

artifact = (DeployArtifactStub) project.getArtifact();

artifact.setFile(file);

String altUserHome = System.getProperty("user.home");

if (altUserHome.equals(originalUserHome)) {
// this is *very* bad!
throw new IllegalStateException(
"Setting 'user.home' system property to alternate value did NOT work. Aborting test.");
}

File sshFile = new File(altUserHome, ".ssh");

System.out.println("Testing .ssh dir: " + sshFile.getCanonicalPath());

// delete first the .ssh folder if existing before executing the mojo
if (sshFile.exists()) {
FileUtils.deleteDirectory(sshFile);
}

mojo.execute();

assertTrue(sshFile.exists());

FileUtils.deleteDirectory(sshFile);
}

public void testLegacyAltDeploymentRepositoryWithDefaultLayout() throws Exception {
DeployMojo mojo = new DeployMojo();

Expand Down

0 comments on commit 6d136a7

Please sign in to comment.