Skip to content

Commit

Permalink
[MINSTALL-177] Streamline the plugin (#32)
Browse files Browse the repository at this point in the history
Original plugin made hoops and loops, instead to perform what it needed to perform. Partly to blame this was unfinished state of MAT API (it was able to install project only).

Installing project is needed in InstallMojo, but InstallFileMojo was forced to make hoops and loops due this, as it was passed one file (and maybe pomFile), and it was forced to create "fake" project, decorate and fake setup it with all whistle and bells, only to get it via MAT to resolver that would "decompose" it back into set of artifacts needing a deploy. So it went this file-artifact-project-artifact route, that made all the logic fragile and overly complicated.

This PR completely reworks m-install-p making it (almost trivially) simple: it does what it needs to do, without any fuss, and does it in streamlined way: InstallMojo will create a list of artifacts out of project and pass it to repository system for deploy, while InstallFileMojo literally prepares just a deployment request,  nothing more. No fuss, no magic, no fake project building etc.

Note: the code in mojos may or may not need to be reusable, but definitely smells like some "Maven API-ish thing". 

Problems: InstallFileMojo implicitly implemented ID validation (thru fake project building), and it revealed the problem that Maven ID (groupId, artifactId) and version validation is deeply buried into maven-model-builder and is NOT reusable at all, hence a light copy of logic (rules for ID allowed characters and version forbidden characters) are copied over here.
  • Loading branch information
cstamas committed Jul 12, 2022
1 parent 9fa9fd5 commit 4dbab72
Show file tree
Hide file tree
Showing 13 changed files with 500 additions and 282 deletions.
35 changes: 17 additions & 18 deletions pom.xml
Expand Up @@ -63,10 +63,10 @@
</distributionManagement>

<properties>
<mavenVersion>3.2.5</mavenVersion>
<slf4jVersion>1.7.32</slf4jVersion>
<aetherVersion>1.1.0</aetherVersion>
<javaVersion>7</javaVersion>
<mavenVersion>3.2.5</mavenVersion>
<aetherVersion>1.0.0.v20140518</aetherVersion> <!-- Maven bound -->
<slf4jVersion>1.7.5</slf4jVersion> <!-- Maven bound -->
<project.build.outputTimestamp>2020-04-07T21:04:00Z</project.build.outputTimestamp>
</properties>

Expand Down Expand Up @@ -97,9 +97,20 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-artifact-transfer</artifactId>
<version>0.13.1</version>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<version>${aetherVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-util</artifactId>
<version>${aetherVersion}</version>
<scope>compile</scope> <!-- To work in Maven versions older than 3.9.0 -->
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>

<!-- dependencies to annotations -->
Expand Down Expand Up @@ -145,18 +156,6 @@
<version>${slf4jVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-api</artifactId>
<version>${aetherVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-util</artifactId>
<version>${aetherVersion}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-impl</artifactId>
Expand Down
18 changes: 18 additions & 0 deletions src/it/install-file-minstall-121-targz/invoker.properties
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.

invoker.goals = org.apache.maven.plugins:maven-install-plugin:${project.version}:install-file
46 changes: 46 additions & 0 deletions src/it/install-file-minstall-121-targz/pom.xml
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->

<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.its.install.121</groupId>
<artifactId>test-targz</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<description>
Test to install a file via install:install-file using
packaging and expected having a different file extension.
</description>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>@project.version@</version>
</plugin>
</plugins>
</build>

</project>
29 changes: 29 additions & 0 deletions src/it/install-file-minstall-121-targz/setup.bsh
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/

import java.io.*;
import java.util.*;

import org.codehaus.plexus.util.*;

File file = new File( localRepositoryPath, "org/apache/maven/its/install/121/test-targz" );
System.out.println( "Deleting " + file );
FileUtils.deleteDirectory( file );

return true;
35 changes: 35 additions & 0 deletions src/it/install-file-minstall-121-targz/test-0.1.pom
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->

<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.maven.its.install.121</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
</parent>

<!-- NOTE: Inherit everything from the parent -->
<artifactId>test-targz</artifactId>

</project>
Binary file not shown.
20 changes: 20 additions & 0 deletions src/it/install-file-minstall-121-targz/test.properties
@@ -0,0 +1,20 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.

file = test-0.1.tar.gz
pomFile = test-0.1.pom
packaging = war
52 changes: 52 additions & 0 deletions src/it/install-file-minstall-121-targz/verify.bsh
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/

import java.io.*;
import java.util.*;

String[] paths =
{
"org/apache/maven/its/install/121/test-targz/maven-metadata-local.xml",
"org/apache/maven/its/install/121/test-targz/1.0/test-targz-1.0.pom",
"org/apache/maven/its/install/121/test-targz/1.0/test-targz-1.0.tar.gz",
};

for ( String path : paths )
{
File file = new File( localRepositoryPath, path );
System.out.println( "Checking for existence of " + file );
if ( !file.isFile() )
{
throw new FileNotFoundException( "Missing: " + file.getAbsolutePath() );
}
}

File file = new File( basedir, "test-0.1.pom" );
if ( !file.isFile() )
{
throw new FileNotFoundException( "Missing: " + file.getAbsolutePath() );
}

File file = new File( basedir, "test-0.1.tar.gz" );
if ( !file.isFile() )
{
throw new FileNotFoundException( "Missing: " + file.getAbsolutePath() );
}

return true;

This file was deleted.

0 comments on commit 4dbab72

Please sign in to comment.