Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Frost2011-05-18 09:49:18 -0400
committerChristopher Frost2011-05-18 09:49:18 -0400
commit8edc8df99724531e5a0168a7f29b8cbe4bc84a4d (patch)
tree3cbd8b57713f806539fceef8588a120196383bd3
parent75a5fc2fea791a5060bc54876b19e3e53a9525ef (diff)
downloadorg.eclipse.virgo.kernel-8edc8df99724531e5a0168a7f29b8cbe4bc84a4d.tar.gz
org.eclipse.virgo.kernel-8edc8df99724531e5a0168a7f29b8cbe4bc84a4d.tar.xz
org.eclipse.virgo.kernel-8edc8df99724531e5a0168a7f29b8cbe4bc84a4d.zip
328630 when checking for installed apps always use canonical uris
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/deployer/model/internal/StandardRuntimeArtifactModel.java44
-rw-r--r--org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/model/internal/StandardRuntimeArtifactModelTests.java145
2 files changed, 177 insertions, 12 deletions
diff --git a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/deployer/model/internal/StandardRuntimeArtifactModel.java b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/deployer/model/internal/StandardRuntimeArtifactModel.java
index b7236995..4703a648 100644
--- a/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/deployer/model/internal/StandardRuntimeArtifactModel.java
+++ b/org.eclipse.virgo.kernel.deployer/src/main/java/org/eclipse/virgo/kernel/deployer/model/internal/StandardRuntimeArtifactModel.java
@@ -11,6 +11,8 @@
package org.eclipse.virgo.kernel.deployer.model.internal;
+import java.io.File;
+import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
@@ -44,6 +46,8 @@ final class StandardRuntimeArtifactModel implements RuntimeArtifactModel {
private static final String URI_PATH_SEPARATOR = "/";
+ private static final String SCHEME_FILE = "file";
+
private final Object monitor = new Object();
private final Map<URI, InstallArtifact> artifactByUri = new HashMap<URI, InstallArtifact>();
@@ -61,8 +65,7 @@ final class StandardRuntimeArtifactModel implements RuntimeArtifactModel {
/**
* {@inheritDoc}
*/
- public DeploymentIdentity add(@NonNull URI location, @NonNull InstallArtifact installArtifact) throws DuplicateFileNameException,
- DuplicateLocationException, DuplicateDeploymentIdentityException, DeploymentException {
+ public DeploymentIdentity add(@NonNull URI location, @NonNull InstallArtifact installArtifact) throws DuplicateFileNameException, DuplicateLocationException, DuplicateDeploymentIdentityException, DeploymentException {
synchronized (this.monitor) {
// Check the precondition and throw an exception if it is violated.
@@ -82,15 +85,15 @@ final class StandardRuntimeArtifactModel implements RuntimeArtifactModel {
}
private void checkLocation(URI location, InstallArtifact installArtifact) throws DuplicateLocationException {
- if (this.artifactByUri.containsKey(location)) {
- InstallArtifact clashingArtifact = this.artifactByUri.get(location);
+ if (this.artifactByUri.containsKey(getCanonicalFileLocation(location))) {
+ InstallArtifact clashingArtifact = getArtifactByUri(location);
throw new DuplicateLocationException(getClashMessage(location, installArtifact, clashingArtifact));
}
}
private void checkFileName(URI location, InstallArtifact installArtifact, String fileName) throws DuplicateFileNameException {
if (this.uriByFileName.containsKey(fileName)) {
- InstallArtifact clashingArtifact = this.artifactByUri.get(this.uriByFileName.get(fileName));
+ InstallArtifact clashingArtifact = getArtifactByUri(this.uriByFileName.get(fileName));
throw new DuplicateFileNameException(getClashMessage(location, installArtifact, clashingArtifact));
}
}
@@ -98,7 +101,7 @@ final class StandardRuntimeArtifactModel implements RuntimeArtifactModel {
private void checkDeploymentIdentity(URI location, InstallArtifact installArtifact, DeploymentIdentity deploymentIdentity)
throws DuplicateDeploymentIdentityException {
if (this.uriByIdentity.containsKey(deploymentIdentity)) {
- InstallArtifact clashingArtifact = this.artifactByUri.get(this.uriByIdentity.get(deploymentIdentity));
+ InstallArtifact clashingArtifact = getArtifactByUri(this.uriByIdentity.get(deploymentIdentity));
throw new DuplicateDeploymentIdentityException(getClashMessage(location, installArtifact, clashingArtifact));
}
}
@@ -127,7 +130,7 @@ final class StandardRuntimeArtifactModel implements RuntimeArtifactModel {
public InstallArtifact get(@NonNull DeploymentIdentity deploymentIdentity) {
synchronized (this.monitor) {
URI location = this.uriByIdentity.get(deploymentIdentity);
- return location == null ? null : this.artifactByUri.get(location);
+ return location == null ? null : getArtifactByUri(location);
}
}
@@ -136,7 +139,7 @@ final class StandardRuntimeArtifactModel implements RuntimeArtifactModel {
*/
public InstallArtifact get(@NonNull URI location) {
synchronized (this.monitor) {
- return this.artifactByUri.get(location);
+ return getArtifactByUri(location);
}
}
@@ -170,7 +173,7 @@ final class StandardRuntimeArtifactModel implements RuntimeArtifactModel {
return null;
}
- InstallArtifact installArtifact = this.artifactByUri.get(location);
+ InstallArtifact installArtifact = getArtifactByUri(location);
Assert.notNull(installArtifact,
"Broken invariant: artifactByUri is missing an entry for URI '%s' but this URI is present in uriByIdentity for '%s'", location,
deploymentIdentity);
@@ -185,15 +188,32 @@ final class StandardRuntimeArtifactModel implements RuntimeArtifactModel {
}
private void updateState(URI location, InstallArtifact installArtifact, String fileName, DeploymentIdentity deploymentIdentity) {
- this.artifactByUri.put(location, installArtifact);
+ this.artifactByUri.put(getCanonicalFileLocation(location), installArtifact);
this.uriByIdentity.put(deploymentIdentity, location);
this.uriByFileName.put(fileName, location);
}
private void removeState(DeploymentIdentity deploymentIdentity, URI location, String fileName) {
- this.artifactByUri.remove(location);
+ this.artifactByUri.remove(getCanonicalFileLocation(location));
this.uriByIdentity.remove(deploymentIdentity);
this.uriByFileName.remove(fileName);
}
-
+
+ private InstallArtifact getArtifactByUri(URI uri){
+ return this.artifactByUri.get(getCanonicalFileLocation(uri));
+ }
+
+ private URI getCanonicalFileLocation(URI uri){
+ if (SCHEME_FILE.equals(uri.getScheme())) {
+ File file = new File(uri);
+ try {
+ return file.getCanonicalFile().toURI();
+ } catch (IOException e) {
+
+ return uri;
+ }
+ } else {
+ return uri;
+ }
+ }
}
diff --git a/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/model/internal/StandardRuntimeArtifactModelTests.java b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/model/internal/StandardRuntimeArtifactModelTests.java
new file mode 100644
index 00000000..9669338b
--- /dev/null
+++ b/org.eclipse.virgo.kernel.deployer/src/test/java/org/eclipse/virgo/kernel/deployer/model/internal/StandardRuntimeArtifactModelTests.java
@@ -0,0 +1,145 @@
+package org.eclipse.virgo.kernel.deployer.model.internal;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Set;
+
+import org.eclipse.virgo.kernel.artifact.fs.ArtifactFS;
+import org.eclipse.virgo.kernel.core.AbortableSignal;
+import org.eclipse.virgo.kernel.deployer.core.DeployUriNormaliser;
+import org.eclipse.virgo.kernel.deployer.core.DeploymentException;
+import org.eclipse.virgo.kernel.deployer.core.DeploymentIdentity;
+import org.eclipse.virgo.kernel.deployer.core.internal.StandardDeploymentIdentity;
+import org.eclipse.virgo.kernel.deployer.model.DuplicateDeploymentIdentityException;
+import org.eclipse.virgo.kernel.deployer.model.DuplicateFileNameException;
+import org.eclipse.virgo.kernel.deployer.model.DuplicateLocationException;
+import org.eclipse.virgo.kernel.install.artifact.InstallArtifact;
+import org.eclipse.virgo.util.common.Tree;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Version;
+
+/**
+ *
+ * StandardRuntimeArtifactModelTests
+ * <p />
+ */
+public class StandardRuntimeArtifactModelTests {
+
+ private final InstallArtifact stubInstallArtifact = new StubInstallArtifact();
+
+ private final DeploymentIdentity deploymentIdentity = new StandardDeploymentIdentity(stubInstallArtifact.getType(), stubInstallArtifact.getName(), stubInstallArtifact.getVersion().toString());
+
+ private StandardRuntimeArtifactModel standardRuntimeArtifactModel;
+
+ private URI testURI;
+
+ @Before
+ public void setUp() throws URISyntaxException, DuplicateFileNameException, DuplicateLocationException, DuplicateDeploymentIdentityException, DeploymentException{
+ this.testURI = new URI("file:/foo/test.bar");
+ this.standardRuntimeArtifactModel = new StandardRuntimeArtifactModel(new DeployUriNormaliser(){
+
+ @Override
+ public URI normalise(URI uri) throws DeploymentException {
+ return uri;
+ }
+
+ });
+
+ this.standardRuntimeArtifactModel.add(this.testURI, this.stubInstallArtifact);
+ }
+
+ @Test
+ public void testGetInstallArtifactByDeploymentIdentity() {
+ assertEquals(this.stubInstallArtifact, this.standardRuntimeArtifactModel.get(this.deploymentIdentity));
+ }
+
+ @Test
+ public void testGetInstallArtifactByLocation() {
+ assertEquals(this.stubInstallArtifact, this.standardRuntimeArtifactModel.get(this.testURI));
+ }
+
+ @Test
+ public void testGetLocationByDeploymentIdentity() {
+ assertEquals(this.testURI, this.standardRuntimeArtifactModel.getLocation(this.deploymentIdentity));
+ }
+
+ @Test
+ public void testDelete() throws DeploymentException {
+ assertEquals(this.stubInstallArtifact, this.standardRuntimeArtifactModel.get(this.deploymentIdentity));
+ this.standardRuntimeArtifactModel.delete(this.deploymentIdentity);
+ assertNull(this.standardRuntimeArtifactModel.get(this.deploymentIdentity));
+ }
+
+
+ private static class StubInstallArtifact implements InstallArtifact {
+
+ private volatile Tree<InstallArtifact> tree;
+
+ public Tree<InstallArtifact> getTree() {
+ return this.tree;
+ }
+
+ public void stop() throws DeploymentException {
+ }
+
+ public void start() throws DeploymentException {
+ start(null);
+ }
+
+ public void start(AbortableSignal signal) throws DeploymentException {
+ }
+
+ public void uninstall() throws DeploymentException {
+ }
+
+ public ArtifactFS getArtifactFS() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getName() {
+ return("test-name");
+ }
+
+ public String getRepositoryName() {
+ return("test-repository");
+ }
+
+ public State getState() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getType() {
+ return("test-type");
+ }
+
+ public Version getVersion() {
+ return Version.emptyVersion;
+ }
+
+ public boolean refresh() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getProperty(String name) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Set<String> getPropertyNames() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String setProperty(String name, String value) {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getScopeName() {
+ return null;
+ }
+ }
+
+}

Back to the top