You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gump.apache.org by bo...@apache.org on 2007/08/22 06:23:31 UTC
svn commit: r568407 - in
/gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo: Main.java
Registry.java resources/ArtifactResource.java resources/Jar.java
restlets/ArtifactAdder.java
Author: bodewig
Date: Tue Aug 21 21:23:22 2007
New Revision: 568407
URL: http://svn.apache.org/viewvc?rev=568407&view=rev
Log:
prepare for SHA1 artifact type
Added:
gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/Registry.java
gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/resources/Jar.java
- copied, changed from r566310, gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/resources/ArtifactResource.java
Removed:
gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/resources/ArtifactResource.java
Modified:
gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/Main.java
gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/restlets/ArtifactAdder.java
Modified: gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/Main.java
URL: http://svn.apache.org/viewvc/gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/Main.java?rev=568407&r1=568406&r2=568407&view=diff
==============================================================================
--- gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/Main.java (original)
+++ gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/Main.java Tue Aug 21 21:23:22 2007
@@ -18,7 +18,7 @@
package org.apache.gump.mvnrepo;
-import org.apache.gump.mvnrepo.resources.ArtifactResource;
+import org.apache.gump.mvnrepo.resources.Jar;
import org.apache.gump.mvnrepo.restlets.ArtifactAdder;
import org.apache.gump.mvnrepo.restlets.ArtifactsForm;
import org.apache.gump.mvnrepo.restlets.Proxy;
@@ -64,7 +64,7 @@
// known artifacts or proxy requests for jars
router.attach(Constants.MVN_ARTIFACT_TEMPLATE,
- ArtifactResource.class);
+ Jar.class);
// simple HTML form to add new artifacts
router.attach("/addartifact.html", new ArtifactsForm());
Added: gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/Registry.java
URL: http://svn.apache.org/viewvc/gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/Registry.java?rev=568407&view=auto
==============================================================================
--- gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/Registry.java (added)
+++ gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/Registry.java Tue Aug 21 21:23:22 2007
@@ -0,0 +1,69 @@
+/*
+ * 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.gump.mvnrepo;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Holds paths for known artifacts.
+ */
+public class Registry {
+
+ // {groupId, artifactId} -> local file name
+ private static final Map<Key, String> knownArtifacts
+ = new HashMap<Key, String>();
+
+ /**
+ * Adds an artifact mapping {group, artifact} -> local file name
+ */
+ public static void addArtifact(String group, String artifactId,
+ String fileName) {
+ knownArtifacts.put(new Key(group, artifactId), fileName);
+ }
+
+ public static String getArtifactPath(String groupId, String artifactId) {
+ return knownArtifacts.get(new Key(groupId, artifactId));
+ }
+
+ private static class Key {
+ private final String groupId;
+ private final String artifactId;
+
+ Key(String groupId, String artifactId) {
+ this.groupId = groupId;
+ this.artifactId = artifactId;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == null || !(o instanceof Key)) {
+ return false;
+ }
+ Key other = (Key) o;
+ return groupId.equals(other.groupId)
+ && artifactId.equals(other.artifactId);
+ }
+
+ @Override
+ public int hashCode() {
+ return groupId.hashCode() + 7 * artifactId.hashCode();
+ }
+ }
+}
\ No newline at end of file
Copied: gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/resources/Jar.java (from r566310, gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/resources/ArtifactResource.java)
URL: http://svn.apache.org/viewvc/gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/resources/Jar.java?p2=gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/resources/Jar.java&p1=gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/resources/ArtifactResource.java&r1=566310&r2=568407&rev=568407&view=diff
==============================================================================
--- gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/resources/ArtifactResource.java (original)
+++ gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/resources/Jar.java Tue Aug 21 21:23:22 2007
@@ -19,6 +19,7 @@
package org.apache.gump.mvnrepo.resources;
import org.apache.gump.mvnrepo.Constants;
+import org.apache.gump.mvnrepo.Registry;
import org.apache.gump.mvnrepo.restlets.Proxy;
import org.restlet.Context;
@@ -30,53 +31,20 @@
import org.restlet.resource.Representation;
import org.restlet.resource.Variant;
-import java.util.Map;
-import java.util.HashMap;
-
/**
* A (jar) artifact served from the local file system if registered by
* Gump or proxied from a real mvn repository.
*/
-public class ArtifactResource extends Resource {
-
- // groupId -> {artifactId -> local file name}
- private static final Map<String, Map<String, String>> knownArtifacts
- = new HashMap<String, Map<String, String>>();
- private static final Object lock = new Object();
-
- /**
- * Adds an artifact mapping {group, artifact} -> local file name
- */
- public static void addArtifact(String group, String artifactId,
- String fileName) {
- Map<String, String> artifactsOfGroup = null;
- synchronized(lock) {
- artifactsOfGroup = knownArtifacts.get(group);
- if (artifactsOfGroup == null) {
- artifactsOfGroup = new HashMap<String, String>();
- knownArtifacts.put(group, artifactsOfGroup);
- }
- }
- artifactsOfGroup.put(artifactId, fileName);
- }
-
- private static String getArtifactPath(String groupId, String artifactId) {
- Map<String, String> artifactsOfGroup = null;
- synchronized(lock) {
- artifactsOfGroup = knownArtifacts.get(groupId);
- }
- return artifactsOfGroup == null ? null
- : artifactsOfGroup.get(artifactId);
- }
+public class Jar extends Resource {
private final String fileName;
- public ArtifactResource(Context ctx, Request request, Response response) {
+ public Jar(Context ctx, Request request, Response response) {
super(ctx, request, response);
- fileName = getArtifactPath((String) request.getAttributes()
- .get(Constants.GROUP_ID),
- (String) request.getAttributes()
- .get(Constants.ARTIFACT_ID));
+ fileName = Registry.getArtifactPath((String) request.getAttributes()
+ .get(Constants.GROUP_ID),
+ (String) request.getAttributes()
+ .get(Constants.ARTIFACT_ID));
getVariants().add(Constants.JAR_VARIANT);
}
Modified: gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/restlets/ArtifactAdder.java
URL: http://svn.apache.org/viewvc/gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/restlets/ArtifactAdder.java?rev=568407&r1=568406&r2=568407&view=diff
==============================================================================
--- gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/restlets/ArtifactAdder.java (original)
+++ gump/mvnrepo/trunk/src/java/org/apache/gump/mvnrepo/restlets/ArtifactAdder.java Tue Aug 21 21:23:22 2007
@@ -19,7 +19,7 @@
package org.apache.gump.mvnrepo.restlets;
import org.apache.gump.mvnrepo.Constants;
-import org.apache.gump.mvnrepo.resources.ArtifactResource;
+import org.apache.gump.mvnrepo.Registry;
import org.restlet.Context;
import org.restlet.Restlet;
@@ -44,11 +44,11 @@
+ "' and file name '"
+ request.getAttributes().get(Constants.FILE_NAME)
+ "'");
- ArtifactResource.addArtifact((String) request.getAttributes()
- .get(Constants.GROUP_ID),
- (String) request.getAttributes()
- .get(Constants.ARTIFACT_ID),
- (String) request.getAttributes()
- .get(Constants.FILE_NAME));
+ Registry.addArtifact((String) request.getAttributes()
+ .get(Constants.GROUP_ID),
+ (String) request.getAttributes()
+ .get(Constants.ARTIFACT_ID),
+ (String) request.getAttributes()
+ .get(Constants.FILE_NAME));
}
}