Skip to content

Commit

Permalink
[MASSEMBLY-967] IT for jar-with-dependencies with main class
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Feb 4, 2024
1 parent b3b7866 commit 008562d
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/it/it-project-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,24 @@ 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/maven-v4_0_0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.plugin.assembly.test</groupId>
<artifactId>it-project-parent</artifactId>
<packaging>pom</packaging>
<version>1</version>

<!-- define versions of dependencies used in ITs -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>@commonsIoVersion@</version>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<pluginManagement>
<plugins>
Expand Down Expand Up @@ -71,14 +82,14 @@ under the License.
</plugins>
</pluginManagement>
</build>

<profiles>
<profile>
<id>testing</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>

<repositories>
<!--
<repository>
Expand Down Expand Up @@ -115,7 +126,7 @@ under the License.
</profile>
<profile>
<id>live</id>

<!-- just avoids the information injected by the testing profile, above. -->
</profile>
</profiles>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version='1.0'?>
<!--
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: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' xmlns='http://maven.apache.org/POM/4.0.0'>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven.plugin.assembly.test</groupId>
<artifactId>it-project-parent</artifactId>
<version>1</version>
</parent>

<artifactId>main-class-and-dependencies</artifactId>
<version>1</version>

<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>test.App</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package test;

/*
* 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 org.apache.commons.io.IOUtils;

/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args ) {
System.out.print( "Hello World!" + IOUtils.LF );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.util.jar.JarEntry
import java.util.jar.JarFile
import java.util.jar.Attributes

def expectedJarEntries = [
"org/apache/commons/io/IOUtils.class",
"test/App.class"
]

File file = new File(basedir, "target/main-class-and-dependencies-1-jar-with-dependencies.jar")
assert file.isFile(): "jar file is missing or a directory."

JarFile jarFile = new JarFile(file)
expectedJarEntries.each {entryName ->
JarEntry jarEntry = jarFile.getJarEntry(entryName)
assert jarEntry != null: "missing jar entry: " + entryName
}

assert "test.App" == jarFile.manifest.mainAttributes.getValue(Attributes.Name.MAIN_CLASS)

0 comments on commit 008562d

Please sign in to comment.