ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1468424 - in /ace/trunk/org.apache.ace.obr: src/org/apache/ace/obr/storage/file/BundleFileStore.java test/org/apache/ace/obr/storage/file/BundleFileStoreTest.java
Date Tue, 16 Apr 2013 14:16:19 GMT
Author: marrs
Date: Tue Apr 16 14:16:19 2013
New Revision: 1468424

URL: http://svn.apache.org/r1468424
Log:
ACE-317 Some typos fixed, added a unit test.

Modified:
    ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/storage/file/BundleFileStore.java
    ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/storage/file/BundleFileStoreTest.java

Modified: ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/storage/file/BundleFileStore.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/storage/file/BundleFileStore.java?rev=1468424&r1=1468423&r2=1468424&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/storage/file/BundleFileStore.java
(original)
+++ ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/storage/file/BundleFileStore.java
Tue Apr 16 14:16:19 2013
@@ -240,10 +240,9 @@ public class BundleFileStore implements 
                 Attributes attributes = manifest.getMainAttributes();
                 if (attributes != null) {
                     String bundleSymbolicName = attributes.getValue(Constants.BUNDLE_SYMBOLICNAME);
-                    String bundleVersion = attributes
-                        .getValue(Constants.BUNDLE_VERSION);
-                    if(bundleSymbolicName != null){
-                        if(bundleVersion == null){
+                    String bundleVersion = attributes.getValue(Constants.BUNDLE_VERSION);
+                    if (bundleSymbolicName != null) {
+                        if (bundleVersion == null) {
                             bundleVersion = "0.0.0";
                         }
                         return new ResourceMetaData(bundleSymbolicName, bundleVersion, "jar");
@@ -269,7 +268,7 @@ public class BundleFileStore implements 
      * @param file the fileName to analyze
      * @return the metadata, or <code>null</code> if the file is not a valid
bundle.
      */
-    private ResourceMetaData getArtifactMetaData(String fileName) {
+    ResourceMetaData getArtifactMetaData(String fileName) {
         
         if (fileName == null || fileName.equals("")) {
             return null;
@@ -284,7 +283,8 @@ public class BundleFileStore implements 
         if (fileNameParts.length > 1) {
             extension = fileNameParts[fileNameParts.length - 1];
             symbolicName = fileName.substring(0, fileName.lastIndexOf('.'));
-        } else {
+        }
+        else {
             symbolicName = fileName;
         }
 
@@ -293,15 +293,16 @@ public class BundleFileStore implements 
         while (dashIndex != -1 && version == null) {
             String versionCandidate = symbolicName.substring(dashIndex + 1);
             Matcher versionMatcher = VERSION_PATTERN.matcher(versionCandidate);
-            if(versionMatcher.matches()){
+            if (versionMatcher.matches()) {
                 symbolicName = symbolicName.substring(0, dashIndex);
                 version = versionCandidate;
-            } else {
+            }
+            else {
                 dashIndex = symbolicName.indexOf('-', dashIndex + 1);                
             }
         }
         
-        if(version == null){
+        if (version == null) {
             version = "0.0.0";
         }
         return new ResourceMetaData(symbolicName, version, extension);
@@ -317,7 +318,7 @@ public class BundleFileStore implements 
     private File getResourceFile(ResourceMetaData metaData) throws IOException {
 
         File resourceFile = null;
-        String[] dirs = metaData.getSymmbolicName().split("\\.");
+        String[] dirs = metaData.getSymbolicName().split("\\.");
         for (String subDir : dirs) {
             if (resourceFile == null) {
                 resourceFile = new File(getWorkingDir(), subDir);
@@ -326,15 +327,15 @@ public class BundleFileStore implements 
                 resourceFile = new File(resourceFile, subDir);
             }
         }
-        if(!resourceFile.exists() && !resourceFile.mkdirs()){
+        if (!resourceFile.exists() && !resourceFile.mkdirs()) {
             throw new IOException("Failed to create store directory");
         }
         
         if (metaData.getExtension() != null && !metaData.getExtension().equals(""))
{
-            resourceFile = new File(resourceFile, metaData.getSymmbolicName() + "-" + metaData.getVersion()
+ "." + metaData.getExtension());
+            resourceFile = new File(resourceFile, metaData.getSymbolicName() + "-" + metaData.getVersion()
+ "." + metaData.getExtension());
         }
         else {
-            resourceFile = new File(resourceFile, metaData.getSymmbolicName() + "-" + metaData.getVersion());
+            resourceFile = new File(resourceFile, metaData.getSymbolicName() + "-" + metaData.getVersion());
         }
         return resourceFile;
     }
@@ -436,21 +437,21 @@ public class BundleFileStore implements 
         private final String m_version;
         private final String m_extension;
         
-        public ResourceMetaData(String bundleSymbolicName, String version, String extension){
+        public ResourceMetaData(String bundleSymbolicName, String version, String extension)
{
             m_bundleSymbolicName = bundleSymbolicName;
             m_version = version;
             m_extension = extension;
         }
         
-        public String getSymmbolicName(){
+        public String getSymbolicName() {
             return m_bundleSymbolicName;
         }
         
-        public String getVersion(){
+        public String getVersion() {
             return m_version;
         }
         
-        public String getExtension(){
+        public String getExtension() {
             return m_extension;
         }
     }

Modified: ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/storage/file/BundleFileStoreTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/storage/file/BundleFileStoreTest.java?rev=1468424&r1=1468423&r2=1468424&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/storage/file/BundleFileStoreTest.java
(original)
+++ ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/storage/file/BundleFileStoreTest.java
Tue Apr 16 14:16:19 2013
@@ -34,10 +34,12 @@ import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
 
 import org.apache.ace.obr.metadata.MetadataGenerator;
+import org.apache.ace.obr.storage.file.BundleFileStore.ResourceMetaData;
 import org.apache.ace.obr.storage.file.constants.OBRFileStoreConstants;
 import org.apache.ace.test.utils.FileUtils;
 import org.apache.ace.test.utils.TestUtils;
 import org.osgi.framework.Constants;
+import org.osgi.framework.Version;
 import org.osgi.service.cm.ConfigurationException;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
@@ -380,6 +382,19 @@ public class BundleFileStoreTest {
         }
         assert !m_metadata.generated() : "After changing the directory, the metadata should
not be regenerated.";
     }
+    
+    @Test(groups = { UNIT })
+    public void checkArtifactMetadataGeneration() {
+    	ResourceMetaData data = m_bundleStore.getArtifactMetaData("resource-1.0.3.xml");
+		assert "resource".equals(data.getSymbolicName()) : "Generated symbolic name should be 'resource',
was " + data.getSymbolicName();
+		assert "1.0.3".equals(data.getVersion()) : "Generated version should be '1.0.3', was "
+ data.getVersion();
+		assert "xml".equals(data.getExtension()) : "Extension should be 'xml', was " + data.getExtension();
+
+		data = m_bundleStore.getArtifactMetaData("maven-artifact-2.3.5-SNAPSHOT.jar");
+		assert "maven-artifact".equals(data.getSymbolicName()) : "Generated symbolic name should
be 'maven-artifact', was " + data.getSymbolicName();
+		assert "2.3.5-SNAPSHOT".equals(data.getVersion()) : "Generated version should be '2.3.5-SNAPSHOT',
was " + data.getVersion();
+		assert "jar".equals(data.getExtension()) : "Extension should be 'jar', was " + data.getExtension();
+    }
 
     private File createTmpResource(String symbolicName, String version) throws IOException
{
         File tmpFile = File.createTempFile("tmpbundle-", "jar");



Mime
View raw message