You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by ma...@apache.org on 2013/07/11 20:30:11 UTC
svn commit: r1502320 - in /ace/trunk:
org.apache.ace.client.repository/src/org/apache/ace/client/repository/helper/base/
org.apache.ace.obr/src/org/apache/ace/obr/metadata/util/
org.apache.ace.obr/src/org/apache/ace/obr/storage/file/ org.apache.ace.obr...
Author: marrs
Date: Thu Jul 11 18:30:11 2013
New Revision: 1502320
URL: http://svn.apache.org/r1502320
Log:
ACE-370 Fixed how artifacts are stored in the OBR, and how template instance names are created. After the refactoring of the OBR, using a more hierarchical model, the existing mechanism failed.
Added:
ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/storage/file/BundleFileStoreSplitTest.java
Modified:
ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/helper/base/VelocityArtifactPreprocessor.java
ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/util/ResourceMetaData.java
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/metadata/util/ResourceMetaDataTest.java
Modified: ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/helper/base/VelocityArtifactPreprocessor.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/helper/base/VelocityArtifactPreprocessor.java?rev=1502320&r1=1502319&r2=1502320&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/helper/base/VelocityArtifactPreprocessor.java (original)
+++ ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/helper/base/VelocityArtifactPreprocessor.java Thu Jul 11 18:30:11 2013
@@ -101,7 +101,7 @@ public class VelocityArtifactPreprocesso
// find the hash for the previous version
String oldHash = getHashForVersion(url, targetID, fromVersion);
-
+
// Note: we do not cache any previously created processed templates, since the call that asks us to approve a new version
// may cross a pending needsNewVersion call.
boolean answer = !newHash.equals(oldHash);
@@ -192,15 +192,16 @@ public class VelocityArtifactPreprocesso
while (dashIndex != -1 && fileVersion.equals("")) {
String versionCandidate = fileName.substring(dashIndex + 1);
Matcher versionMatcher = VERSION_PATTERN.matcher(versionCandidate);
- if(versionMatcher.matches()){
+ if (versionMatcher.matches()) {
fileName = fileName.substring(0, dashIndex);
fileVersion = versionCandidate;
- } else {
+ }
+ else {
dashIndex = fileName.indexOf(fileName, dashIndex);
}
}
- fileName = fileName + ".target-" + targetID + "-" + targetVersion + fileExtension;
+ fileName = fileName + "_" + targetID + "_" + targetVersion + fileExtension;
return fileName;
}
@@ -213,12 +214,33 @@ public class VelocityArtifactPreprocesso
* @return a hash
*/
private String getHashForVersion(String url, String target, String version) {
+ String hash = null;
String key = createHashKey(url, target, version);
Reference<String> ref = m_cachedHashes.get(key);
- String hash = (ref != null) ? ref.get() : null;
+ if (ref != null) {
+ hash = ref.get();
+ }
+ if (hash == null) {
+ try {
+ hash = hash(getBytesFromUrl(getFullUrl(url, target, version)));
+ m_cachedHashes.put(key, new WeakReference<String>(hash));
+ }
+ catch (IOException e) {
+ return null;
+ }
+ }
+ else {
+ hash = ref.get();
+ }
return hash;
}
+ private String getFullUrl(String url, String targetID, String version) {
+ String filename = getFilename(url, targetID, version);
+ String result = url.substring(0, url.lastIndexOf('/') + 1) + filename;
+ return result;
+ }
+
/**
* Adds a hash to the cache.
*
Modified: ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/util/ResourceMetaData.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/util/ResourceMetaData.java?rev=1502320&r1=1502319&r2=1502320&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/util/ResourceMetaData.java (original)
+++ ace/trunk/org.apache.ace.obr/src/org/apache/ace/obr/metadata/util/ResourceMetaData.java Thu Jul 11 18:30:11 2013
@@ -93,8 +93,7 @@ public class ResourceMetaData {
* @return the metadata
*/
public static ResourceMetaData getArtifactMetaData(String fileName) {
-
- if(fileName == null || fileName.equals("")){
+ if (fileName == null || fileName.equals("")) {
return null;
}
String symbolicName = null;
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=1502320&r1=1502319&r2=1502320&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 Thu Jul 11 18:30:11 2013
@@ -29,7 +29,9 @@ import java.math.BigInteger;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
import java.util.Dictionary;
+import java.util.List;
import java.util.Stack;
import org.apache.ace.obr.metadata.MetadataGenerator;
@@ -89,8 +91,9 @@ public class BundleFileStore implements
public String put(InputStream data, String fileName) throws IOException {
- if(fileName == null)
+ if (fileName == null) {
fileName = "";
+ }
File tempFile = downloadToTempFile(data);
ResourceMetaData metaData = ResourceMetaData.getBundleMetaData(tempFile);
@@ -250,27 +253,52 @@ public class BundleFileStore implements
*/
private File getResourceFile(ResourceMetaData metaData) throws IOException {
- File resourceFile = null;
- String[] dirs = metaData.getSymbolicName().split("\\.");
- for (String subDir : dirs) {
- if (resourceFile == null) {
- resourceFile = new File(getWorkingDir(), subDir);
- }
- else {
- resourceFile = new File(resourceFile, subDir);
- }
+ File resourceDirectory = getWorkingDir();
+ String[] dirs = split(metaData.getSymbolicName());
+ for (int i = 0; i < (dirs.length - 1); i++) {
+ String subDir = dirs[i];
+ resourceDirectory = new File(resourceDirectory, subDir);
}
- if (!resourceFile.exists() && !resourceFile.mkdirs()) {
+ if (!resourceDirectory.exists() && !resourceDirectory.mkdirs()) {
throw new IOException("Failed to create store directory");
}
- if (metaData.getExtension() != null && !metaData.getExtension().equals("")) {
- resourceFile = new File(resourceFile, metaData.getSymbolicName() + "-" + metaData.getVersion() + "." + metaData.getExtension());
+ String name = metaData.getSymbolicName();
+ String version = metaData.getVersion();
+ if (version != null && !version.equals("") && !version.equals("0.0.0")) {
+ name += "-" + version;
+ }
+ String extension = metaData.getExtension();
+ if (extension != null && !extension.equals("")) {
+ name += "." + extension;
}
- else {
- resourceFile = new File(resourceFile, metaData.getSymbolicName() + "-" + metaData.getVersion());
+ return new File(resourceDirectory, name);
+ }
+
+ /**
+ * Splits a name into parts, breaking at all dots as long as what's behind the dot resembles a
+ * Java package name (ie. it starts with a lowercase character).
+ *
+ * @param name the name to split
+ * @return an array of parts
+ */
+ public static String[] split(String name) {
+ List<String> result = new ArrayList<String>();
+ int startPos = 0;
+ for (int i = 0; i < (name.length() - 1); i++) {
+ if (name.charAt(i) == '.') {
+ if (Character.isLowerCase(name.charAt(i + 1))) {
+ result.add(name.substring(startPos, i));
+ i++;
+ startPos = i;
+ }
+ else {
+ break;
+ }
+ }
}
- return resourceFile;
+ result.add(name.substring(startPos));
+ return result.toArray(new String[result.size()]);
}
/**
Modified: ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/metadata/util/ResourceMetaDataTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/metadata/util/ResourceMetaDataTest.java?rev=1502320&r1=1502319&r2=1502320&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/metadata/util/ResourceMetaDataTest.java (original)
+++ ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/metadata/util/ResourceMetaDataTest.java Thu Jul 11 18:30:11 2013
@@ -39,6 +39,14 @@ public class ResourceMetaDataTest {
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();
}
+
+ @Test(groups = { UNIT })
+ public void checkConfigurationTemplateMetadataGeneration() throws Exception {
+ ResourceMetaData data = ResourceMetaData.getArtifactMetaData("org.foo.configuration-1.0.0.xml-target-1-2.0.0.xml");
+ assert "org.foo.configuration-1.0.0.xml-target-1".equals(data.getSymbolicName()) : "Generated symbolic name should be 'org.foo.configuration-1.0.0.xml-target-1', was " + data.getSymbolicName();
+ assert "2.0.0".equals(data.getVersion()) : "Generated version should be '2.0.0', was " + data.getVersion();
+ assert "xml".equals(data.getExtension()) : "Extension should be 'xml', was " + data.getExtension();
+ }
@Test(groups = { UNIT })
public void checkBundleMetadataGeneration() throws Exception {
Added: ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/storage/file/BundleFileStoreSplitTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/storage/file/BundleFileStoreSplitTest.java?rev=1502320&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/storage/file/BundleFileStoreSplitTest.java (added)
+++ ace/trunk/org.apache.ace.obr/test/org/apache/ace/obr/storage/file/BundleFileStoreSplitTest.java Thu Jul 11 18:30:11 2013
@@ -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.
+ */
+package org.apache.ace.obr.storage.file;
+
+import static org.apache.ace.test.utils.TestUtils.UNIT;
+
+import static org.testng.Assert.*;
+import org.testng.annotations.Test;
+
+public class BundleFileStoreSplitTest {
+ @Test(groups = { UNIT })
+ public void testBasicSplit() throws Exception {
+ assertEquals(BundleFileStore.split("org.foo"), new String[] {"org", "foo"});
+ assertEquals(BundleFileStore.split("org.foo-1.0.0.SNAPSHOT"), new String[] {"org", "foo-1.0.0.SNAPSHOT"});
+ assertEquals(BundleFileStore.split("org.foo.bar.of.chocolate"), new String[] {"org", "foo", "bar", "of", "chocolate"});
+ assertEquals(BundleFileStore.split("org.foo.1"), new String[] {"org", "foo.1"});
+ assertEquals(BundleFileStore.split("org.foo-1.0.org.foo-1.0"), new String[] {"org", "foo-1.0.org.foo-1.0"});
+ assertEquals(BundleFileStore.split(""), new String[] {""});
+ assertEquals(BundleFileStore.split("."), new String[] {"."});
+ assertEquals(BundleFileStore.split("abc."), new String[] {"abc."});
+ }
+}