Skip to content

Commit f3d22f9

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 0a4e929 commit f3d22f9

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-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;
@@ -243,6 +242,27 @@ private void _testProvidedManifest(String pomLocation) throws Exception
243242
assertTrue("Invalid Classpath in manifest : " + manifest, manifest.contains("Class-Path: custom.jar"));
244243
}
245244

245+
@Test
246+
public void test006_UseDefaultManifestFile() throws Exception
247+
{
248+
IProject project = importProject("projects/mavenarchiver/mavenarchiver-p006/pom.xml");
249+
waitForJobsToComplete();
250+
251+
IFile manifestFile = project.getFile("src/main/resources/META-INF/MANIFEST.MF");
252+
assertTrue("The manifest was deleted", manifestFile.exists());
253+
254+
// trigger a full build
255+
project.build( IncrementalProjectBuilder.FULL_BUILD, monitor );
256+
waitForJobsToComplete();
257+
assertNoErrors(project);
258+
259+
IFile generatedManifestFile = project.getFile("target/classes/META-INF/MANIFEST.MF");
260+
assertTrue("A manifest is missing", generatedManifestFile.exists());
261+
262+
String manifest =getAsString(generatedManifestFile);
263+
assertTrue("Built-By is invalid:"+manifest, manifest.contains("Built-By: You know who"));
264+
}
265+
246266
public void testMECLIPSEWTP163_ParentMustBeResolved()
247267
throws Exception
248268
{

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

+6
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,12 @@ private void reflectManifestGeneration(MavenProject mavenProject, MojoExecution
430430
Xpp3Dom originalConfig = mojoExecution.getConfiguration();
431431
Xpp3Dom customConfig = Xpp3DomUtils.mergeXpp3Dom(new Xpp3Dom("configuration"), originalConfig);
432432

433+
Xpp3Dom useDefaultManifestFile = customConfig.getChild("useDefaultManifestFile");
434+
if (useDefaultManifestFile != null && Boolean.parseBoolean(useDefaultManifestFile.getValue())) {
435+
//<useDefaultManifestFile>true</useDefaultManifestFile> -> assume manifest is provided or generated by other mojo
436+
return;
437+
}
438+
433439
//Add custom manifest entries
434440
customizeManifest(customConfig, mavenProject);
435441

0 commit comments

Comments
 (0)