Skip to content

Commit 4dbab72

Browse files
authored
[MINSTALL-177] Streamline the plugin (#32)
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.
1 parent 9fa9fd5 commit 4dbab72

File tree

13 files changed

+500
-282
lines changed

13 files changed

+500
-282
lines changed

pom.xml

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@
6363
</distributionManagement>
6464

6565
<properties>
66-
<mavenVersion>3.2.5</mavenVersion>
67-
<slf4jVersion>1.7.32</slf4jVersion>
68-
<aetherVersion>1.1.0</aetherVersion>
6966
<javaVersion>7</javaVersion>
67+
<mavenVersion>3.2.5</mavenVersion>
68+
<aetherVersion>1.0.0.v20140518</aetherVersion> <!-- Maven bound -->
69+
<slf4jVersion>1.7.5</slf4jVersion> <!-- Maven bound -->
7070
<project.build.outputTimestamp>2020-04-07T21:04:00Z</project.build.outputTimestamp>
7171
</properties>
7272

@@ -97,9 +97,20 @@
9797
<scope>provided</scope>
9898
</dependency>
9999
<dependency>
100-
<groupId>org.apache.maven.shared</groupId>
101-
<artifactId>maven-artifact-transfer</artifactId>
102-
<version>0.13.1</version>
100+
<groupId>org.eclipse.aether</groupId>
101+
<artifactId>aether-api</artifactId>
102+
<version>${aetherVersion}</version>
103+
<scope>provided</scope>
104+
</dependency>
105+
<dependency>
106+
<groupId>org.eclipse.aether</groupId>
107+
<artifactId>aether-util</artifactId>
108+
<version>${aetherVersion}</version>
109+
<scope>compile</scope> <!-- To work in Maven versions older than 3.9.0 -->
110+
</dependency>
111+
<dependency>
112+
<groupId>org.codehaus.plexus</groupId>
113+
<artifactId>plexus-utils</artifactId>
103114
</dependency>
104115

105116
<!-- dependencies to annotations -->
@@ -145,18 +156,6 @@
145156
<version>${slf4jVersion}</version>
146157
<scope>test</scope>
147158
</dependency>
148-
<dependency>
149-
<groupId>org.eclipse.aether</groupId>
150-
<artifactId>aether-api</artifactId>
151-
<version>${aetherVersion}</version>
152-
<scope>test</scope>
153-
</dependency>
154-
<dependency>
155-
<groupId>org.eclipse.aether</groupId>
156-
<artifactId>aether-util</artifactId>
157-
<version>${aetherVersion}</version>
158-
<scope>test</scope>
159-
</dependency>
160159
<dependency>
161160
<groupId>org.eclipse.aether</groupId>
162161
<artifactId>aether-impl</artifactId>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
invoker.goals = org.apache.maven.plugins:maven-install-plugin:${project.version}:install-file
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
-->
21+
22+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
26+
<groupId>org.apache.maven.its.install.121</groupId>
27+
<artifactId>test-targz</artifactId>
28+
<version>1.0</version>
29+
<packaging>jar</packaging>
30+
31+
<description>
32+
Test to install a file via install:install-file using
33+
packaging and expected having a different file extension.
34+
</description>
35+
36+
<build>
37+
<plugins>
38+
<plugin>
39+
<groupId>org.apache.maven.plugins</groupId>
40+
<artifactId>maven-install-plugin</artifactId>
41+
<version>@project.version@</version>
42+
</plugin>
43+
</plugins>
44+
</build>
45+
46+
</project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import java.io.*;
21+
import java.util.*;
22+
23+
import org.codehaus.plexus.util.*;
24+
25+
File file = new File( localRepositoryPath, "org/apache/maven/its/install/121/test-targz" );
26+
System.out.println( "Deleting " + file );
27+
FileUtils.deleteDirectory( file );
28+
29+
return true;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
Licensed to the Apache Software Foundation (ASF) under one
5+
or more contributor license agreements. See the NOTICE file
6+
distributed with this work for additional information
7+
regarding copyright ownership. The ASF licenses this file
8+
to you under the Apache License, Version 2.0 (the
9+
"License"); you may not use this file except in compliance
10+
with the License. You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0
13+
14+
Unless required by applicable law or agreed to in writing,
15+
software distributed under the License is distributed on an
16+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
KIND, either express or implied. See the License for the
18+
specific language governing permissions and limitations
19+
under the License.
20+
-->
21+
22+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
26+
<parent>
27+
<groupId>org.apache.maven.its.install.121</groupId>
28+
<artifactId>parent</artifactId>
29+
<version>1.0</version>
30+
</parent>
31+
32+
<!-- NOTE: Inherit everything from the parent -->
33+
<artifactId>test-targz</artifactId>
34+
35+
</project>
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
file = test-0.1.tar.gz
19+
pomFile = test-0.1.pom
20+
packaging = war
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import java.io.*;
21+
import java.util.*;
22+
23+
String[] paths =
24+
{
25+
"org/apache/maven/its/install/121/test-targz/maven-metadata-local.xml",
26+
"org/apache/maven/its/install/121/test-targz/1.0/test-targz-1.0.pom",
27+
"org/apache/maven/its/install/121/test-targz/1.0/test-targz-1.0.tar.gz",
28+
};
29+
30+
for ( String path : paths )
31+
{
32+
File file = new File( localRepositoryPath, path );
33+
System.out.println( "Checking for existence of " + file );
34+
if ( !file.isFile() )
35+
{
36+
throw new FileNotFoundException( "Missing: " + file.getAbsolutePath() );
37+
}
38+
}
39+
40+
File file = new File( basedir, "test-0.1.pom" );
41+
if ( !file.isFile() )
42+
{
43+
throw new FileNotFoundException( "Missing: " + file.getAbsolutePath() );
44+
}
45+
46+
File file = new File( basedir, "test-0.1.tar.gz" );
47+
if ( !file.isFile() )
48+
{
49+
throw new FileNotFoundException( "Missing: " + file.getAbsolutePath() );
50+
}
51+
52+
return true;

src/main/java/org/apache/maven/plugins/install/AbstractInstallMojo.java

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)