From 377ed681464a9d070d5f3fcf2a3b695b5a7a08b5 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Fri, 20 Jan 2006 03:09:04 +0000 Subject: [PATCH] applet for allowing upload of the md5 of a local file to the webapp for searching on the checksum Still to do: investigate requirement for java.policy, and additional InvocationTargetException on Firefox git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@370715 13f79535-47bb-0310-9956-ffa450edef68 --- maven-repository-artifact-applet/pom.xml | 39 +++++++ .../src/keystore/keystore | Bin 0 -> 1279 bytes .../repository/applet/ChecksumApplet.java | 96 ++++++++++++++++++ maven-repository-webapp/pom.xml | 30 ++++++ .../web/action/PackageSearchAction.java | 23 ++++- .../src/main/webapp/WEB-INF/jsp/form.jspf | 46 +++++++++ .../src/main/webapp/WEB-INF/jsp/index.jsp | 4 +- .../src/main/webapp/WEB-INF/jsp/results.jsp | 4 +- pom.xml | 6 ++ 9 files changed, 240 insertions(+), 8 deletions(-) create mode 100644 maven-repository-artifact-applet/pom.xml create mode 100644 maven-repository-artifact-applet/src/keystore/keystore create mode 100644 maven-repository-artifact-applet/src/main/java/org/apache/maven/repository/applet/ChecksumApplet.java create mode 100644 maven-repository-webapp/src/main/webapp/WEB-INF/jsp/form.jspf diff --git a/maven-repository-artifact-applet/pom.xml b/maven-repository-artifact-applet/pom.xml new file mode 100644 index 000000000..3d4eef26d --- /dev/null +++ b/maven-repository-artifact-applet/pom.xml @@ -0,0 +1,39 @@ + + 4.0.0 + + org.apache.maven.repository + maven-repository-manager + 1.0-SNAPSHOT + + maven-repository-artifact-applet + Maven Repository Manager Artifact Applet + + Applet for performing local operations on files such as creating a checksum of an artifact + before uploading it. + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.1-SNAPSHOT + + src/keystore/keystore + mykey + password + password + + + + + sign + + + + + + + diff --git a/maven-repository-artifact-applet/src/keystore/keystore b/maven-repository-artifact-applet/src/keystore/keystore new file mode 100644 index 0000000000000000000000000000000000000000..52cea0c2881a4973f602e78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/main/java/org/apache/maven/repository/applet/ChecksumApplet.java b/maven-repository-artifact-applet/src/main/java/org/apache/maven/repository/applet/ChecksumApplet.java new file mode 100644 index 000000000..b102d70d3 --- /dev/null +++ b/maven-repository-artifact-applet/src/main/java/org/apache/maven/repository/applet/ChecksumApplet.java @@ -0,0 +1,96 @@ +package org.apache.maven.repository.applet; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed 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.applet.Applet; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +/** + * TODO: Description. + * + * @author Brett Porter + */ +public class ChecksumApplet + extends Applet +{ + private static final int CHECKSUM_BUFFER_SIZE = 8192; + + private static final int BYTE_MASK = 0xFF; + + public void init() + { + super.init(); + } + + public String generateMd5( String file ) + throws IOException, NoSuchAlgorithmException + { + MessageDigest digest = MessageDigest.getInstance( "MD5" ); + + InputStream fis = new FileInputStream( file ); + try + { + byte[] buffer = new byte[CHECKSUM_BUFFER_SIZE]; + int numRead; + do + { + numRead = fis.read( buffer ); + if ( numRead > 0 ) + { + digest.update( buffer, 0, numRead ); + } + } + while ( numRead != -1 ); + } + finally + { + fis.close(); + } + + return byteArrayToHexStr( digest.digest() ); + } + + private static String byteArrayToHexStr( byte[] data ) + { + String output = ""; + + for ( int cnt = 0; cnt < data.length; cnt++ ) + { + //Deposit a byte into the 8 lsb of an int. + int tempInt = data[cnt] & BYTE_MASK; + + //Get hex representation of the int as a string. + String tempStr = Integer.toHexString( tempInt ); + + //Append a leading 0 if necessary so that each hex string will contain 2 characters. + if ( tempStr.length() == 1 ) + { + tempStr = "0" + tempStr; + } + + //Concatenate the two characters to the output string. + output = output + tempStr; + } + + return output.toUpperCase(); + } +} \ No newline at end of file diff --git a/maven-repository-webapp/pom.xml b/maven-repository-webapp/pom.xml index 3163a3224..6dc4c77fe 100644 --- a/maven-repository-webapp/pom.xml +++ b/maven-repository-webapp/pom.xml @@ -19,6 +19,12 @@ org.apache.maven.repository maven-repository-indexer + + org.apache.maven.repository + maven-repository-artifact-applet + + provided + maven-repository-webapp @@ -31,6 +37,30 @@ / + + org.codehaus.mojo + dependency-maven-plugin + + + copy + process-resources + + copy + + + + + ${project.groupId} + maven-repository-artifact-applet + ${project.version} + src/main/webapp + maven-repository-artifact-applet.jar + + + + + + diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/PackageSearchAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/PackageSearchAction.java index dd882138b..81f92c96e 100644 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/PackageSearchAction.java +++ b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/PackageSearchAction.java @@ -42,6 +42,8 @@ public class PackageSearchAction { private String packageName; + private String md5; + /** * @plexus.requirement */ @@ -62,7 +64,19 @@ public class PackageSearchAction public String execute() throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException { - if ( packageName == null || packageName.length() == 0 ) + String searchTerm; + String key; + if ( packageName != null && packageName.length() != 0 ) + { + searchTerm = packageName; + key = "packages"; + } + else if ( md5 != null && md5.length() != 0 ) + { + searchTerm = md5; + key = "md5"; + } + else { return ERROR; } @@ -78,7 +92,7 @@ public class PackageSearchAction ArtifactRepositoryIndexSearcher searcher = factory.createArtifactRepositoryIndexSearcher( index ); - artifacts = searcher.search( new SinglePhraseQuery( "packages", packageName ) ); + artifacts = searcher.search( new SinglePhraseQuery( key, searchTerm ) ); return SUCCESS; } @@ -88,6 +102,11 @@ public class PackageSearchAction this.packageName = packageName; } + public void setMd5( String md5 ) + { + this.md5 = md5; + } + public List getArtifacts() { return artifacts; diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/form.jspf b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/form.jspf new file mode 100644 index 000000000..ebff97902 --- /dev/null +++ b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/form.jspf @@ -0,0 +1,46 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed 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. + ~ + --%> + + + +

Search by MD5 (select an artifact): +

+ + + +
+ + + +

+ +

Search by Java Package: +

+ + +
+

+ + diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/index.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/index.jsp index d24f950f8..202871712 100644 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/index.jsp +++ b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/index.jsp @@ -8,9 +8,7 @@

Maven Repository Manager

-
- -
+<%@ include file="form.jspf" %> \ No newline at end of file diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp index 9b560c3e3..f644419a4 100644 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp +++ b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp @@ -24,9 +24,7 @@

Maven Repository Manager

-
- -
+<%@include file="form.jspf"%> diff --git a/pom.xml b/pom.xml index fa5cc6e17..2619ad736 100644 --- a/pom.xml +++ b/pom.xml @@ -130,6 +130,7 @@ maven-repository-application + maven-repository-artifact-applet maven-repository-converter maven-repository-discovery maven-repository-reports-standard @@ -244,6 +245,11 @@ maven-repository-utils ${pom.version} + + org.apache.maven.repository + maven-repository-artifact-applet + ${pom.version} + -- 2.39.5