Skip to content

Commit 96a6615

Browse files
author
Erwin Tratar
committed
generate META-INF/MANIFEST.MF if useDefaultManifestFile is set
The MANIFEST.MF might be provided as a resource or generated by a previous step, e.g. the bnd-maven-plugin and must neither be writtern or overwritten if <useDefaultManifestFile> is configured to true
1 parent 5a285e5 commit 96a6615

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project>
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.sonatype.m2e.mavenarchiver.tests</groupId>
5+
<artifactId>mavenarchiver-p006</artifactId>
6+
<version>1.0.0-SNAPSHOT</version>
7+
<build>
8+
<plugins>
9+
<plugin>
10+
<artifactId>maven-compiler-plugin</artifactId>
11+
<version>2.0.2</version>
12+
</plugin>
13+
<plugin>
14+
<artifactId>maven-jar-plugin</artifactId>
15+
<version>2.2</version>
16+
<configuration>
17+
<useDefaultManifestFile>true</useDefaultManifestFile>
18+
</configuration>
19+
</plugin>
20+
<plugin>
21+
<artifactId>maven-resources-plugin</artifactId>
22+
<version>2.4.1</version>
23+
</plugin>
24+
<plugin>
25+
<artifactId>maven-surefire-plugin</artifactId>
26+
<version>2.4.3</version>
27+
</plugin>
28+
</plugins>
29+
</build>
30+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Built-By: You know who
2+
Class-Path: custom.jar

org.sonatype.m2e.mavenarchiver.tests/src/org/sonatype/m2e/mavenarchiver/MavenArchiverTest.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.eclipse.core.resources.IncrementalProjectBuilder;
1212
import org.eclipse.core.runtime.CoreException;
1313
import org.eclipse.core.runtime.IPath;
14-
import org.eclipse.core.runtime.NullProgressMonitor;
1514
import org.eclipse.m2e.core.MavenPlugin;
1615
import org.eclipse.m2e.core.embedder.ArtifactKey;
1716
import org.eclipse.m2e.core.internal.IMavenConstants;
@@ -261,6 +260,27 @@ private void _testProvidedManifest(String pomLocation) throws Exception
261260
assertTrue("Invalid Classpath in manifest : " + manifest, manifest.contains("Class-Path: custom.jar"));
262261
}
263262

263+
@Test
264+
public void test006_UseDefaultManifestFile() throws Exception
265+
{
266+
IProject project = importProject("projects/mavenarchiver/mavenarchiver-p006/pom.xml");
267+
waitForJobsToComplete();
268+
269+
IFile manifestFile = project.getFile("src/main/resources/META-INF/MANIFEST.MF");
270+
assertTrue("The manifest was deleted", manifestFile.exists());
271+
272+
// trigger a full build
273+
project.build( IncrementalProjectBuilder.FULL_BUILD, monitor );
274+
waitForJobsToComplete();
275+
assertNoErrors(project);
276+
277+
IFile generatedManifestFile = project.getFile("target/classes/META-INF/MANIFEST.MF");
278+
assertTrue("A manifest is missing", generatedManifestFile.exists());
279+
280+
String manifest =getAsString(generatedManifestFile);
281+
assertTrue("Built-By is invalid:"+manifest, manifest.contains("Built-By: You know who"));
282+
}
283+
264284
public void testMECLIPSEWTP163_ParentMustBeResolved()
265285
throws Exception
266286
{

org.sonatype.m2e.mavenarchiver/src/org/sonatype/m2e/mavenarchiver/internal/AbstractMavenArchiverConfigurator.java

+11
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,17 @@ private void reflectManifestGeneration(MavenProject mavenProject, MojoExecution
433433
Xpp3Dom originalConfig = mojoExecution.getConfiguration();
434434
Xpp3Dom customConfig = Xpp3DomUtils.mergeXpp3Dom(new Xpp3Dom("configuration"), originalConfig);
435435

436+
Xpp3Dom useDefaultManifestFile = customConfig.getChild("useDefaultManifestFile");
437+
if (useDefaultManifestFile != null && Boolean.parseBoolean(useDefaultManifestFile.getValue())) {
438+
//<useDefaultManifestFile>true</useDefaultManifestFile> -> assume manifest is provided or generated by other mojo
439+
return;
440+
}
441+
Xpp3Dom archiveConfig = customConfig.getChild("archive");
442+
if (archiveConfig != null && archiveConfig.getChild("manifestFile") != null) {
443+
//<archive><manifestFile>..</manifestFile></archive> -> assume manifest is provided or generated by other mojo
444+
return;
445+
}
446+
436447
//Add custom manifest entries
437448
customizeManifest(customConfig, mavenProject);
438449

0 commit comments

Comments
 (0)