Author: khmarbaise
Date: Sun Apr 10 11:51:15 2016
New Revision: 1738422
URL: http://svn.apache.org/viewvc?rev=1738422&view=rev
Log:
[MSHARED-511] Using structures to keep insertion order for MANIFEST.MF
o Replaced HashMap with LinkedHashMap to keep insertion order.
Added appropriate test to check this.
o Upgraded JUnit from 4.10 to 4.12
o Added assertj-core for appropriate tests
o Fixed formatting issue and added missing LICENSE header.
Added:
maven/shared/trunk/maven-archiver/src/test/java/org/apache/maven/archiver/MavenArchiveConfigurationTest.java
Modified:
maven/shared/trunk/maven-archiver/pom.xml
maven/shared/trunk/maven-archiver/src/main/java/org/apache/maven/archiver/ManifestSection.java
maven/shared/trunk/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiveConfiguration.java
maven/shared/trunk/maven-archiver/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
Modified: maven/shared/trunk/maven-archiver/pom.xml
URL:
http://svn.apache.org/viewvc/maven/shared/trunk/maven-archiver/pom.xml?rev=1738422&r1=1738421&r2=1738422&view=diff
==============================================================================
--- maven/shared/trunk/maven-archiver/pom.xml (original)
+++ maven/shared/trunk/maven-archiver/pom.xml Sun Apr 10 11:51:15 2016
@@ -100,7 +100,13 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
- <version>4.10</version>
+ <version>4.12</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <version>1.7.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Modified:
maven/shared/trunk/maven-archiver/src/main/java/org/apache/maven/archiver/ManifestSection.java
URL:
http://svn.apache.org/viewvc/maven/shared/trunk/maven-archiver/src/main/java/org/apache/maven/archiver/ManifestSection.java?rev=1738422&r1=1738421&r2=1738422&view=diff
==============================================================================
---
maven/shared/trunk/maven-archiver/src/main/java/org/apache/maven/archiver/ManifestSection.java
(original)
+++
maven/shared/trunk/maven-archiver/src/main/java/org/apache/maven/archiver/ManifestSection.java
Sun Apr 10 11:51:15 2016
@@ -19,7 +19,7 @@ package org.apache.maven.archiver;
* under the License.
*/
-import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
/**
@@ -30,7 +30,7 @@ public class ManifestSection
private String name = null;
- private Map<String, String> manifestEntries = new HashMap<String,
String>();
+ private Map<String, String> manifestEntries = new LinkedHashMap<String,
String>();
/**
* @param key The key of the manifest entry.
Modified:
maven/shared/trunk/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiveConfiguration.java
URL:
http://svn.apache.org/viewvc/maven/shared/trunk/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiveConfiguration.java?rev=1738422&r1=1738421&r2=1738422&view=diff
==============================================================================
---
maven/shared/trunk/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiveConfiguration.java
(original)
+++
maven/shared/trunk/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiveConfiguration.java
Sun Apr 10 11:51:15 2016
@@ -20,8 +20,8 @@ package org.apache.maven.archiver;
*/
import java.io.File;
-import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -44,11 +44,12 @@ public class MavenArchiveConfiguration
private File manifestFile;
+ //TODO: Rename this attribute to manifestConfiguration;
private ManifestConfiguration manifest;
- private Map<String, String> manifestEntries = new HashMap<String,
String>();
+ private Map<String, String> manifestEntries = new LinkedHashMap<String,
String>();
- private List<ManifestSection> manifestSections = new
ArrayList<ManifestSection>();
+ private List<ManifestSection> manifestSections = new
LinkedList<ManifestSection>();
/**
* @since 2.2
@@ -111,6 +112,7 @@ public class MavenArchiveConfiguration
/**
* @return {@link #manifest}
*/
+ //TODO: Change the name of this method into getManifestConfiguration()
public ManifestConfiguration getManifest()
{
if ( manifest == null )
Added:
maven/shared/trunk/maven-archiver/src/test/java/org/apache/maven/archiver/MavenArchiveConfigurationTest.java
URL:
http://svn.apache.org/viewvc/maven/shared/trunk/maven-archiver/src/test/java/org/apache/maven/archiver/MavenArchiveConfigurationTest.java?rev=1738422&view=auto
==============================================================================
---
maven/shared/trunk/maven-archiver/src/test/java/org/apache/maven/archiver/MavenArchiveConfigurationTest.java
(added)
+++
maven/shared/trunk/maven-archiver/src/test/java/org/apache/maven/archiver/MavenArchiveConfigurationTest.java
Sun Apr 10 11:51:15 2016
@@ -0,0 +1,78 @@
+package org.apache.maven.archiver;
+
+/*
+ * 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 static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.entry;
+
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Karl Heinz Marbaise <a
href="mailto:[email protected]">[email protected]</a>.
+ */
+public class MavenArchiveConfigurationTest
+{
+
+ private ManifestConfiguration manifestConfiguration;
+
+ private MavenArchiveConfiguration archive;
+
+ @Before
+ public void before()
+ {
+ this.manifestConfiguration = new ManifestConfiguration();
+ archive = new MavenArchiveConfiguration();
+ archive.setManifest( manifestConfiguration );
+ archive.setForced( false );
+ archive.setCompress( false );
+ archive.setIndex( false );
+ }
+
+ @Test
+ public void addingSingleEntryShouldBeReturned()
+ {
+ archive.addManifestEntry( "key1", "value1" );
+ Map<String, String> manifestEntries = archive.getManifestEntries();
+ assertThat( manifestEntries ).containsExactly( entry( "key1", "value1"
) );
+ }
+
+ @Test
+ public void addingTwoEntriesShouldBeReturnedInInsertOrder()
+ {
+ archive.addManifestEntry( "key1", "value1" );
+ archive.addManifestEntry( "key2", "value2" );
+ Map<String, String> manifestEntries = archive.getManifestEntries();
+ assertThat( manifestEntries ).containsExactly( entry( "key1", "value1"
), entry( "key2", "value2" ) );
+ }
+
+ @Test
+ public void addingThreeEntriesShouldBeReturnedInInsertOrder()
+ {
+ archive.addManifestEntry( "key1", "value1" );
+ archive.addManifestEntry( "key2", "value2" );
+ archive.addManifestEntry( "key3", "value3" );
+ Map<String, String> manifestEntries = archive.getManifestEntries();
+ assertThat( manifestEntries ).containsExactly( entry( "key1", "value1"
), entry( "key2", "value2" ),
+ entry( "key3", "value3"
) );
+ }
+}
Modified:
maven/shared/trunk/maven-archiver/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
URL:
http://svn.apache.org/viewvc/maven/shared/trunk/maven-archiver/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java?rev=1738422&r1=1738421&r2=1738422&view=diff
==============================================================================
---
maven/shared/trunk/maven-archiver/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
(original)
+++
maven/shared/trunk/maven-archiver/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
Sun Apr 10 11:51:15 2016
@@ -1,5 +1,24 @@
package org.apache.maven.archiver;
+/*
+ * 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.File;
import java.io.IOException;
import java.io.InputStream;
@@ -44,24 +63,6 @@ import org.codehaus.plexus.archiver.jar.
import org.codehaus.plexus.archiver.jar.ManifestException;
import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.util.DefaultRepositorySystemSession;
-/*
- * 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.
- */
public class MavenArchiverTest
extends TestCase
@@ -185,7 +186,7 @@ public class MavenArchiverTest
Model model = new Model();
model.setArtifactId( "dummy" );
- MavenProject project = new MavenProject( model )
+ MavenProject project = new MavenProject( model)
{
public List<String> getRuntimeClasspathElements()
{
@@ -214,7 +215,7 @@ public class MavenArchiverTest
}
finally
{
- //noinspection ResultOfMethodCallIgnored
+ // noinspection ResultOfMethodCallIgnored
tempFile.delete();
}
}
@@ -415,8 +416,9 @@ public class MavenArchiverTest
config.setForced( true );
config.getManifest().setAddDefaultImplementationEntries( true );
config.addManifestEntry( "Description", project.getDescription() );
- // config.addManifestEntry( "EntryWithTab", " foo tab " + ( '\u0009' )
+ ( '\u0009' ) + " bar tab" + (
- // '\u0009' ) );
+ // config.addManifestEntry( "EntryWithTab", " foo tab " + ( '\u0009' )
+ ( '\u0009' )
+ // + " bar tab" + ( // '\u0009'
+ // ) );
archiver.createArchive( session, project, config );
assertTrue( jarFile.exists() );
@@ -443,7 +445,7 @@ public class MavenArchiverTest
config.getManifest().setAddDefaultImplementationEntries( true );
config.getManifest().setAddDefaultSpecificationEntries( true );
- //noinspection deprecation
+ // noinspection deprecation
MavenSession session = getDummySessionWithoutMavenVersion();
archiver.createArchive( session, project, config );
assertTrue( jarFile.exists() );
@@ -727,8 +729,7 @@ public class MavenArchiverTest
config.getManifest().setMainClass( "org.apache.maven.Foo" );
config.getManifest().setAddClasspath( true );
config.getManifest().setClasspathLayoutType(
ManifestConfiguration.CLASSPATH_LAYOUT_TYPE_CUSTOM );
- config.getManifest().setCustomClasspathLayout(
-
"${artifact.groupIdPath}/${artifact.artifactId}/${artifact.version}/TEST-${artifact.artifactId}-${artifact.version}${dashClassifier?}.${artifact.extension}"
);
+ config.getManifest().setCustomClasspathLayout(
"${artifact.groupIdPath}/${artifact.artifactId}/${artifact.version}/TEST-${artifact.artifactId}-${artifact.version}${dashClassifier?}.${artifact.extension}"
);
archiver.createArchive( session, project, config );
assertTrue( jarFile.exists() );
Manifest manifest = archiver.getManifest( session, project, config );
@@ -763,8 +764,7 @@ public class MavenArchiverTest
config.getManifest().setMainClass( "org.apache.maven.Foo" );
config.getManifest().setAddClasspath( true );
config.getManifest().setClasspathLayoutType(
ManifestConfiguration.CLASSPATH_LAYOUT_TYPE_CUSTOM );
- config.getManifest().setCustomClasspathLayout(
-
"${artifact.groupIdPath}/${artifact.artifactId}/${artifact.baseVersion}/TEST-${artifact.artifactId}-${artifact.version}${dashClassifier?}.${artifact.extension}"
);
+ config.getManifest().setCustomClasspathLayout(
"${artifact.groupIdPath}/${artifact.artifactId}/${artifact.baseVersion}/TEST-${artifact.artifactId}-${artifact.version}${dashClassifier?}.${artifact.extension}"
);
archiver.createArchive( session, project, config );
assertTrue( jarFile.exists() );
@@ -802,8 +802,7 @@ public class MavenArchiverTest
config.getManifest().setMainClass( "org.apache.maven.Foo" );
config.getManifest().setAddClasspath( true );
config.getManifest().setClasspathLayoutType(
ManifestConfiguration.CLASSPATH_LAYOUT_TYPE_CUSTOM );
- config.getManifest().setCustomClasspathLayout(
-
"${artifact.groupIdPath}/${artifact.artifactId}/${artifact.baseVersion}/TEST-${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension}"
);
+ config.getManifest().setCustomClasspathLayout(
"${artifact.groupIdPath}/${artifact.artifactId}/${artifact.baseVersion}/TEST-${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension}"
);
archiver.createArchive( session, project, config );
assertTrue( jarFile.exists() );
Manifest manifest = archiver.getManifest( session, project, config );
@@ -822,7 +821,7 @@ public class MavenArchiverTest
}
public void testDefaultPomProperties()
- throws Exception
+ throws Exception
{
MavenSession session = getDummySession();
MavenProject project = getDummyProject();
@@ -841,7 +840,8 @@ public class MavenArchiverTest
final String version = project.getVersion();
JarFile virtJarFile = new JarFile( jarFile );
- ZipEntry pomPropertiesEntry = virtJarFile.getEntry( "META-INF/maven/"
+ groupId + "/" + artifactId + "/pom.properties" );
+ ZipEntry pomPropertiesEntry =
+ virtJarFile.getEntry( "META-INF/maven/" + groupId + "/" +
artifactId + "/pom.properties" );
assertNotNull( pomPropertiesEntry );
InputStream is = virtJarFile.getInputStream( pomPropertiesEntry );
@@ -855,7 +855,7 @@ public class MavenArchiverTest
}
public void testCustomPomProperties()
- throws Exception
+ throws Exception
{
MavenSession session = getDummySession();
MavenProject project = getDummyProject();
@@ -876,7 +876,8 @@ public class MavenArchiverTest
final String version = project.getVersion();
JarFile virtJarFile = new JarFile( jarFile );
- ZipEntry pomPropertiesEntry = virtJarFile.getEntry( "META-INF/maven/"
+ groupId + "/" + artifactId + "/pom.properties" );
+ ZipEntry pomPropertiesEntry =
+ virtJarFile.getEntry( "META-INF/maven/" + groupId + "/" +
artifactId + "/pom.properties" );
assertNotNull( pomPropertiesEntry );
InputStream is = virtJarFile.getInputStream( pomPropertiesEntry );
@@ -885,8 +886,8 @@ public class MavenArchiverTest
assertEquals( groupId, p.getProperty( "groupId" ) );
assertEquals( artifactId, p.getProperty( "artifactId" ) );
assertEquals( version, p.getProperty( "version" ) );
- assertEquals( "1337", p.getProperty("build.revision" ) );
- assertEquals( "tags/0.1.1", p.getProperty("build.branch" ) );
+ assertEquals( "1337", p.getProperty( "build.revision" ) );
+ assertEquals( "tags/0.1.1", p.getProperty( "build.branch" ) );
virtJarFile.close();
}
@@ -941,13 +942,12 @@ public class MavenArchiverTest
model.setVersion( "0.1.1" );
final MavenProject project = new MavenProject( model );
- project.setExtensionArtifacts( Collections.<Artifact>emptySet() );
- project.setRemoteArtifactRepositories(
Collections.<ArtifactRepository>emptyList() );
- project.setPluginArtifactRepositories(
Collections.<ArtifactRepository>emptyList() );
+ project.setExtensionArtifacts( Collections.<Artifact> emptySet() );
+ project.setRemoteArtifactRepositories(
Collections.<ArtifactRepository> emptyList() );
+ project.setPluginArtifactRepositories(
Collections.<ArtifactRepository> emptyList() );
return project;
}
-
private MockArtifact getMockArtifact3()
{
MockArtifact artifact3 = new MockArtifact();
@@ -1123,7 +1123,6 @@ public class MavenArchiverTest
MavenExecutionResult result = new DefaultMavenExecutionResult();
-
RepositorySystemSession rss = new DefaultRepositorySystemSession();
return new MavenSession( container, rss, request, result );