You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by og...@apache.org on 2009/04/23 00:57:04 UTC
svn commit: r767705 [4/31] - in /maven/mercury/trunk/mercury-core: ./ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/maven/ src/main/java/org/apache/maven/mercury/
src/main/java/org/apache/maven/merc...
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/builder/api/MetadataReaderException.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/builder/api/MetadataReaderException.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/builder/api/MetadataReaderException.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/builder/api/MetadataReaderException.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,65 @@
+/**
+ * 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.maven.mercury.builder.api;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class MetadataReaderException
+ extends Exception
+{
+ private static final long serialVersionUID = 3693299588183676110L;
+
+ /**
+ *
+ */
+ public MetadataReaderException()
+ {
+ }
+
+ /**
+ * @param message
+ */
+ public MetadataReaderException( String message )
+ {
+ super( message );
+ }
+
+ /**
+ * @param cause
+ */
+ public MetadataReaderException( Throwable cause )
+ {
+ super( cause );
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public MetadataReaderException( String message, Throwable cause )
+ {
+ super( message, cause );
+ }
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/builder/api/MetadataReaderException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/builder/api/MetadataReaderException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/AbstractStreamVerifier.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/AbstractStreamVerifier.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/AbstractStreamVerifier.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/AbstractStreamVerifier.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,45 @@
+/**
+ * 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.maven.mercury.crypto.api;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public abstract class AbstractStreamVerifier
+{
+ protected StreamVerifierAttributes attributes;
+
+ /**
+ * @param attributes
+ */
+ public AbstractStreamVerifier( StreamVerifierAttributes attributes )
+ {
+ this.attributes = attributes;
+ }
+
+ public StreamVerifierAttributes getAttributes()
+ {
+ return attributes;
+ }
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/AbstractStreamVerifier.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/AbstractStreamVerifier.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/AbstractStreamVerifierFactory.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/AbstractStreamVerifierFactory.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/AbstractStreamVerifierFactory.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/AbstractStreamVerifierFactory.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,45 @@
+/**
+ * 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.maven.mercury.crypto.api;
+
+/**
+ * Helper for implementing stream verifier factories, takes care of attributes
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public abstract class AbstractStreamVerifierFactory
+{
+ protected StreamVerifierAttributes attributes;
+
+ /**
+ * @param attributes
+ */
+ public AbstractStreamVerifierFactory( StreamVerifierAttributes attributes )
+ {
+ this.attributes = attributes;
+ }
+
+ public StreamVerifierAttributes getAttributes()
+ {
+ return attributes == null ? new StreamVerifierAttributes() : attributes;
+ }
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/AbstractStreamVerifierFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/AbstractStreamVerifierFactory.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamObserver.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamObserver.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamObserver.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamObserver.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,35 @@
+/**
+ * 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.maven.mercury.crypto.api;
+
+public interface StreamObserver
+{
+ void byteReady(int b)
+ throws StreamObserverException;
+
+ void bytesReady(byte[]b, int off, int len)
+ throws StreamObserverException;
+
+ void setLength(long length);
+ long getLength();
+
+ void setLastModified(String time);
+ String getLastModified();
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamObserver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamObserver.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamObserverException.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamObserverException.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamObserverException.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamObserverException.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,72 @@
+/**
+ * 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.maven.mercury.crypto.api;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class StreamObserverException
+ extends Exception
+{
+
+ /**
+ *
+ */
+ public StreamObserverException()
+ {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param message
+ */
+ public StreamObserverException(
+ String message )
+ {
+ super( message );
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param cause
+ */
+ public StreamObserverException(
+ Throwable cause )
+ {
+ super( cause );
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public StreamObserverException(
+ String message,
+ Throwable cause )
+ {
+ super( message, cause );
+ // TODO Auto-generated constructor stub
+ }
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamObserverException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamObserverException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamObserverFactory.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamObserverFactory.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamObserverFactory.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamObserverFactory.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,25 @@
+/**
+ * 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.maven.mercury.crypto.api;
+
+public interface StreamObserverFactory
+{
+ public StreamObserver newInstance()
+ throws StreamObserverException;
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamObserverFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamObserverFactory.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifier.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifier.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifier.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifier.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,40 @@
+/**
+ * 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.maven.mercury.crypto.api;
+
+
+public interface StreamVerifier
+extends StreamObserver
+{
+ public StreamVerifierAttributes getAttributes();
+
+ public String getSignature()
+ throws StreamVerifierException;
+
+ // to verify stream: initSignature( InputStream signatureStream ), process stream, then verifySignature()
+ public void initSignature( String signatureStream )
+ throws StreamVerifierException;
+
+ public boolean verifySignature()
+ throws StreamVerifierException;
+
+// public boolean verifySignature( String signature )
+// throws StreamVerifierException;
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifier.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifier.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifierAttributes.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifierAttributes.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifierAttributes.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifierAttributes.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,73 @@
+/**
+ * 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.maven.mercury.crypto.api;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class StreamVerifierAttributes
+{
+ protected boolean isLenient = true;
+ protected boolean isSufficient = false;
+ protected String extension = "none";
+ protected String digestAlgorithm = "SHA-1";
+
+ /**
+ *
+ */
+ public StreamVerifierAttributes( String extension, boolean isLenient, boolean isSufficient)
+ {
+ this.extension = extension;
+ this.isLenient = isLenient;
+ this.isSufficient = isSufficient;
+ }
+
+ /**
+ *
+ */
+ public StreamVerifierAttributes()
+ {
+ }
+
+ public boolean isLenient()
+ {
+ return isLenient;
+ }
+
+ public boolean isSufficient()
+ {
+ return isSufficient;
+ }
+
+ public String getExtension()
+ {
+ return extension == null
+ ? extension
+ : extension.startsWith( "." )
+ ? extension
+ : "."+extension
+ ;
+ }
+
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifierAttributes.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifierAttributes.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifierException.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifierException.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifierException.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifierException.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,70 @@
+/**
+ * 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.maven.mercury.crypto.api;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class StreamVerifierException
+extends StreamObserverException
+{
+
+ /**
+ *
+ */
+ public StreamVerifierException()
+ {
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param message
+ */
+ public StreamVerifierException( String message )
+ {
+ super( message );
+ }
+
+ /**
+ * @param cause
+ */
+ public StreamVerifierException(
+ Throwable cause )
+ {
+ super( cause );
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public StreamVerifierException(
+ String message,
+ Throwable cause )
+ {
+ super( message, cause );
+ // TODO Auto-generated constructor stub
+ }
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifierException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifierException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifierFactory.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifierFactory.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifierFactory.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifierFactory.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,27 @@
+/**
+ * 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.maven.mercury.crypto.api;
+
+public interface StreamVerifierFactory
+{
+ public StreamVerifier newInstance()
+ throws StreamVerifierException;
+
+ public String getDefaultExtension();
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifierFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/api/StreamVerifierFactory.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/basic/ChecksumCalculator.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/basic/ChecksumCalculator.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/basic/ChecksumCalculator.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/basic/ChecksumCalculator.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,42 @@
+/**
+ * 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.maven.mercury.crypto.basic;
+
+
+
+public class ChecksumCalculator
+{
+ private static final byte[] __HEX_DIGITS = "0123456789abcdef".getBytes();
+
+ public static String encodeToAsciiHex( byte[] bytes )
+ {
+ int l = bytes.length;
+
+ byte[] raw = new byte[l * 2];
+
+ for ( int i = 0, j = 0; i < l; i++ )
+ {
+ raw[j++] = __HEX_DIGITS[ ( 0xF0 & bytes[i] ) >>> 4 ];
+ raw[j++] = __HEX_DIGITS[ 0x0F & bytes[i] ];
+ }
+
+ return new String( raw );
+ }
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/basic/ChecksumCalculator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/basic/ChecksumCalculator.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/cli/Sign.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/cli/Sign.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/cli/Sign.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/cli/Sign.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,32 @@
+/*
+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.maven.mercury.crypto.cli;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class Sign
+{
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/cli/Sign.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/cli/Sign.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/Messages.properties
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/Messages.properties?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/Messages.properties (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/Messages.properties Wed Apr 22 22:56:48 2009
@@ -0,0 +1,45 @@
+#
+# 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.
+#
+
+null.input.stream=input stream should not be null
+bad.key.id=bad hex key id: {0}
+
+no.secret.key=no secret key {0} in the specified keyring
+no.public.key=no public key {0} in the specified keyring
+
+null.private.key=supplied key cannot be null
+
+null.verify.signature=out of sequence call to verify signature: verifier has not been initialized yet
+
+bad.verify.signature.state=out of sequence call to produce signature: verifier has not been initialized yet
+
+no.signatures.in.stream=no signatures found in the input streamn
+no.objects.in.stream=no pgp objects found in the input streamn
+
+bad.factory.init.verify=cannot initialize signature verification factory without trusted ring
+bad.factory.init.verify.empty=trusted ring read in is null, cannot proceed
+bad.factory.init.generate=cannot initialize signature generation factory without secret key
+
+no.stream.processor=neither signature generator nor signature verifier has been initialized. Don't know what to do.
+no.trusted.ring=trusted ring seem to be empty. There is no one I can trust, so signature verification is pointless.
+no.signature.string=there is signature supplied, so signature verification is pointless.
+
+null.ring=public ring cannot be null
+
+null.os=output stream cannot be null
\ No newline at end of file
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/Messages.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/Messages.properties
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/PgpHelper.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/PgpHelper.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/PgpHelper.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/PgpHelper.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,238 @@
+/**
+ * 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.maven.mercury.crypto.pgp;
+
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.math.BigInteger;
+import java.security.Security;
+import java.util.Iterator;
+
+import org.apache.maven.mercury.crypto.api.StreamObserverException;
+import org.apache.maven.mercury.crypto.api.StreamVerifierAttributes;
+import org.apache.maven.mercury.crypto.api.StreamVerifierException;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.openpgp.PGPCompressedData;
+import org.bouncycastle.openpgp.PGPException;
+import org.bouncycastle.openpgp.PGPObjectFactory;
+import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
+import org.bouncycastle.openpgp.PGPSecretKey;
+import org.bouncycastle.openpgp.PGPSecretKeyRing;
+import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
+import org.bouncycastle.openpgp.PGPSignature;
+import org.bouncycastle.openpgp.PGPSignatureList;
+import org.bouncycastle.openpgp.PGPUtil;
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+/**
+ * PGP helper - collection of utility methods, loosely based on one of the
+ * Bouncy Castle's SignedFileProcessor.java
+ *
+ */
+public class PgpHelper
+{
+ public static final String PROVIDER = "BC";
+ public static final String EXTENSION = "asc";
+
+ private static final byte [] _buf = new byte[10240];
+
+
+ private static final Language LANG = new DefaultLanguage( PgpHelper.class );
+ //---------------------------------------------------------------------------------
+ static
+ {
+ Security.addProvider( new BouncyCastleProvider() );
+ }
+ //---------------------------------------------------------------------------------
+ /**
+ * load a key ring stream and find the secret key by hex id
+ *
+ * @param in PGP keystore
+ * @param hexId key id
+ * @return
+ * @throws IOException
+ * @throws PGPException
+ */
+ public static PGPSecretKeyRing readKeyRing( InputStream in, String hexId )
+ throws IOException, PGPException
+ {
+ if( in == null )
+ throw new IllegalArgumentException( LANG.getMessage( "null.input.stream" ) );
+
+ if( hexId == null || hexId.length() < 16 )
+ throw new IllegalArgumentException( LANG.getMessage( "bad.key.id", hexId ) );
+
+ long id = hexToId( hexId );
+
+ in = PGPUtil.getDecoderStream( in );
+
+ PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection( in );
+
+ Iterator<PGPSecretKeyRing> ringIt = pgpSec.getKeyRings();
+
+ while( ringIt.hasNext() )
+ {
+ PGPSecretKeyRing keyRing = ringIt.next();
+ PGPSecretKey key = keyRing.getSecretKey( id );
+ if( key != null )
+ return keyRing;
+ }
+
+ throw new IllegalArgumentException( LANG.getMessage( "no.secret.key", hexId ) );
+ }
+ //---------------------------------------------------------------------------------
+ public static long hexToId( String hexId )
+ {
+ BigInteger bi = new BigInteger( hexId, 16 );
+ return bi.longValue();
+ }
+ //---------------------------------------------------------------------------------
+ public static long getKeyId( InputStream inSig )
+ throws IOException, PGPException
+ {
+ PGPSignature sig = readSignature( inSig );
+
+ return sig.getKeyID();
+ }
+ //---------------------------------------------------------------------------------
+ public static PGPSignature readSignature( InputStream inS )
+ throws IOException, PGPException
+ {
+ if( inS == null )
+ throw new IllegalArgumentException( "null.input.stream" );
+
+ InputStream in = inS;
+ in = PGPUtil.getDecoderStream( in );
+
+ PGPObjectFactory pgpObjectFactory = new PGPObjectFactory( in );
+ PGPSignatureList sigList = null;
+
+ Object pgpObject = pgpObjectFactory.nextObject();
+
+ if( pgpObject == null )
+ throw new PGPException( LANG.getMessage( "no.objects.in.stream" ) );
+
+ if( pgpObject instanceof PGPCompressedData )
+ {
+ PGPCompressedData cd = (PGPCompressedData)pgpObject;
+
+ pgpObjectFactory = new PGPObjectFactory( cd.getDataStream() );
+
+ sigList = (PGPSignatureList)pgpObjectFactory.nextObject();
+ }
+ else
+ {
+ sigList = (PGPSignatureList)pgpObject;
+ }
+
+ if( sigList.size() < 1 )
+ throw new PGPException( LANG.getMessage( "no.signatures.in.stream" ) );
+
+ PGPSignature sig = sigList.get(0);
+
+ return sig;
+ }
+ //---------------------------------------------------------------------------------
+ public static String streamToString( InputStream in )
+ throws IOException
+ {
+ if( in == null )
+ return null;
+
+ ByteArrayOutputStream ba = new ByteArrayOutputStream();
+ int b = 0;
+ while( (b = in.read()) != -1 )
+ ba.write( b );
+
+ return ba.toString();
+ }
+ //---------------------------------------------------------------------------------
+ public static String fileToString( String fileName )
+ throws IOException
+ {
+ FileInputStream fis = null;
+ try
+ {
+ fis = new FileInputStream( fileName );
+ return streamToString( fis );
+ }
+ finally
+ {
+ if( fis != null ) try { fis.close(); } catch( Exception any ) {}
+ }
+ }
+ //---------------------------------------------------------------------------------
+ public static final boolean verifyStream( InputStream in, InputStream asc, InputStream publicKeyRingStream )
+ throws IOException, StreamObserverException
+ {
+ StreamVerifierAttributes attributes = new StreamVerifierAttributes(PgpStreamVerifierFactory.DEFAULT_EXTENSION, false, true);
+
+ PgpStreamVerifierFactory svf = new PgpStreamVerifierFactory( attributes, publicKeyRingStream );
+ String sig = PgpHelper.streamToString( asc );
+
+ return verifyStream( in, sig, svf );
+ }
+ //---------------------------------------------------------------------------------
+ public static final boolean verifyStream( InputStream in, String sig, PgpStreamVerifierFactory factory )
+ throws IOException, StreamObserverException
+ {
+
+ PgpStreamVerifier sv = (PgpStreamVerifier)factory.newInstance();
+
+ sv.initSignature( sig );
+
+ int nBytes = -1;
+ while( (nBytes = in.read(_buf)) != -1 )
+ sv.bytesReady( _buf, 0, nBytes );
+
+ boolean verified = sv.verifySignature();
+
+ return verified;
+ }
+
+ public static final PGPPublicKeyRingCollection readPublicRing( InputStream in )
+ throws IOException, PGPException
+ {
+ if( in == null )
+ return null;
+
+ PGPPublicKeyRingCollection res = new PGPPublicKeyRingCollection( PGPUtil.getDecoderStream( in ) );
+
+ return res;
+ }
+
+ public static final void writePublicRing( PGPPublicKeyRingCollection prc, OutputStream out )
+ throws IOException
+ {
+ if( prc == null )
+ throw new IllegalArgumentException( LANG.getMessage( "null.ring" ) );
+
+ if( out == null )
+ throw new IllegalArgumentException( LANG.getMessage( "null.os" ) );
+
+ prc.encode( out );
+
+ }
+ //---------------------------------------------------------------------------------
+ //---------------------------------------------------------------------------------
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/PgpHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/PgpHelper.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/PgpStreamVerifier.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/PgpStreamVerifier.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/PgpStreamVerifier.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/PgpStreamVerifier.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,242 @@
+/**
+ * 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.maven.mercury.crypto.pgp;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.security.SignatureException;
+
+import org.apache.maven.mercury.crypto.api.AbstractStreamVerifier;
+import org.apache.maven.mercury.crypto.api.StreamObserverException;
+import org.apache.maven.mercury.crypto.api.StreamVerifier;
+import org.apache.maven.mercury.crypto.api.StreamVerifierAttributes;
+import org.apache.maven.mercury.crypto.api.StreamVerifierException;
+import org.bouncycastle.bcpg.ArmoredOutputStream;
+import org.bouncycastle.bcpg.BCPGOutputStream;
+import org.bouncycastle.openpgp.PGPPrivateKey;
+import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
+import org.bouncycastle.openpgp.PGPSignature;
+import org.bouncycastle.openpgp.PGPSignatureGenerator;
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+/**
+ * lightweight pgp stream encoder, created one per stream
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class PgpStreamVerifier
+extends AbstractStreamVerifier
+implements StreamVerifier
+{
+ private static final Language LANG = new DefaultLanguage( PgpStreamVerifier.class );
+
+ private PGPPublicKeyRingCollection trustedPublicKeyRing;
+
+ private PGPSignatureGenerator signatureGenerator;
+
+ private PGPSignature signature;
+
+ private String signatureString;
+
+ private long length = -1;
+
+ private String lastModified;
+
+ //-----------------------------------------------------------------------------------
+ public PgpStreamVerifier( StreamVerifierAttributes attributes )
+ {
+ super( attributes );
+ }
+ //-----------------------------------------------------------------------------------
+ public void init( PGPPublicKeyRingCollection trustedPublicKeyRing )
+ {
+ this.trustedPublicKeyRing = trustedPublicKeyRing;
+ }
+ //-----------------------------------------------------------------------------------
+ public void init( PGPPrivateKey privateKey, int algorithm, int digestAlgorithm )
+ throws StreamVerifierException
+ {
+ if( privateKey == null )
+ throw new IllegalArgumentException( LANG.getMessage( "null.private.key" ));
+
+ try
+ {
+ signatureGenerator = new PGPSignatureGenerator( algorithm
+ , digestAlgorithm
+ , PgpHelper.PROVIDER
+ );
+ signatureGenerator.initSign( PGPSignature.BINARY_DOCUMENT, privateKey );
+
+ signatureString = null;
+ }
+ catch( Exception e )
+ {
+ throw new StreamVerifierException(e);
+ }
+ }
+
+ //-----------------------------------------------------------------------------------
+ public void byteReady( int b )
+ throws StreamObserverException
+ {
+ try
+ {
+ if( signature == null )
+ {
+ if( signatureGenerator == null )
+ throw new StreamVerifierException( LANG.getMessage( "no.stream.processor" ) );
+ signatureGenerator.update( (byte)b );
+ }
+ else
+ signature.update( (byte)b );
+ }
+ catch( SignatureException e )
+ {
+ throw new StreamObserverException(e);
+ }
+ }
+
+ //-----------------------------------------------------------------------------------
+ public void bytesReady( byte[] b, int off, int len )
+ throws StreamObserverException
+ {
+ try
+ {
+ if( signature == null )
+ {
+ if( signatureGenerator == null )
+ throw new StreamVerifierException( LANG.getMessage( "no.stream.processor" ) );
+ signatureGenerator.update( b, off, len );
+ }
+ else
+ signature.update( b, off, len );
+ }
+ catch( SignatureException e )
+ {
+ throw new StreamObserverException(e);
+ }
+ }
+ //-----------------------------------------------------------------------------------
+ public void initSignature( String signatureString )
+ throws StreamVerifierException
+ {
+ try
+ {
+ if( trustedPublicKeyRing == null )
+ throw new StreamVerifierException( LANG.getMessage( "no.trusted.ring" ) );
+
+ if( signatureString == null || signatureString.length() < 1 )
+ throw new StreamVerifierException( LANG.getMessage( "no.signature.string" ) );
+
+ signature = PgpHelper.readSignature( new ByteArrayInputStream( signatureString.getBytes() ) );
+
+ if( signature == null )
+ throw new StreamVerifierException( "no.signatures.in.stream" );
+
+ signature.initVerify( trustedPublicKeyRing.getPublicKey( signature.getKeyID() ), PgpHelper.PROVIDER );
+ }
+ catch( Exception e )
+ {
+ throw new StreamVerifierException(e);
+ }
+
+ if( signature == null )
+ throw new StreamVerifierException("no.signatures.in.stream");
+
+ }
+ //-----------------------------------------------------------------------------------
+ public boolean verifySignature()
+ throws StreamVerifierException
+ {
+
+ if( signature == null )
+ throw new StreamVerifierException( LANG.getMessage( "null.verify.signature" ));
+
+ try
+ {
+ boolean res = signature.verify();
+ return res;
+ }
+ catch( Exception e )
+ {
+ throw new StreamVerifierException( e );
+ }
+ }
+
+ //-----------------------------------------------------------------------------------
+ public String getSignature()
+ throws StreamVerifierException
+ {
+ if( signatureString != null )
+ return signatureString;
+
+ if( signatureGenerator == null )
+ throw new StreamVerifierException("bad.verify.signature.state");
+
+ BCPGOutputStream signaturePgpBytes = null;
+ try
+ {
+ ByteArrayOutputStream signatureBytes = new ByteArrayOutputStream();
+ ArmoredOutputStream aos = new ArmoredOutputStream( signatureBytes );
+ signaturePgpBytes = new BCPGOutputStream( aos );
+ signatureGenerator.generate().encode( signaturePgpBytes );
+ signaturePgpBytes.finish();
+ aos.flush();
+ aos.close();
+ signatureString = signatureBytes.toString();
+ }
+ catch( Exception e )
+ {
+ throw new StreamVerifierException( e );
+ }
+ finally
+ {
+ if( signaturePgpBytes != null ) try { signaturePgpBytes.close(); } catch( Exception any ) {}
+ }
+
+ signatureGenerator = null;
+
+ return signatureString;
+ }
+ //-----------------------------------------------------------------------------------
+ public long getLength()
+ {
+ return length;
+ }
+ //-----------------------------------------------------------------------------------
+ public void setLength(long length)
+ {
+ this.length = length;
+
+ }
+ //-----------------------------------------------------------------------------------
+ public String getLastModified()
+ {
+ return lastModified;
+ }
+ //-----------------------------------------------------------------------------------
+ public void setLastModified(String time)
+ {
+ lastModified = time;
+
+ }
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/PgpStreamVerifier.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/PgpStreamVerifier.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/PgpStreamVerifierFactory.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/PgpStreamVerifierFactory.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/PgpStreamVerifierFactory.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/PgpStreamVerifierFactory.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,155 @@
+/**
+ * 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.maven.mercury.crypto.pgp;
+
+import java.io.InputStream;
+
+import org.apache.maven.mercury.crypto.api.AbstractStreamVerifierFactory;
+import org.apache.maven.mercury.crypto.api.StreamVerifier;
+import org.apache.maven.mercury.crypto.api.StreamVerifierAttributes;
+import org.apache.maven.mercury.crypto.api.StreamVerifierException;
+import org.apache.maven.mercury.crypto.api.StreamVerifierFactory;
+import org.bouncycastle.openpgp.PGPPrivateKey;
+import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
+import org.bouncycastle.openpgp.PGPSecretKey;
+import org.bouncycastle.openpgp.PGPSecretKeyRing;
+import org.bouncycastle.openpgp.PGPUtil;
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class PgpStreamVerifierFactory
+extends AbstractStreamVerifierFactory
+implements StreamVerifierFactory
+{
+
+ public static final String DEFAULT_EXTENSION = PgpHelper.EXTENSION;
+
+ private static final Language LANG = new DefaultLanguage( PgpStreamVerifierFactory.class );
+
+ private PGPPublicKeyRingCollection trustedPublicKeyRing;
+
+ private PGPPrivateKey privateKey;
+
+ private int algorithm = 0;
+
+ private int digestAlgorithm = PGPUtil.SHA1;
+
+ //--------------------------------------------------------------------------------------------
+ public PgpStreamVerifierFactory( StreamVerifierAttributes attributes
+ , InputStream trustedPublicKeyRingStream
+ )
+ throws StreamVerifierException
+ {
+ super( attributes );
+ init( trustedPublicKeyRingStream );
+
+ }
+ //--------------------------------------------------------------------------------------------
+ public PgpStreamVerifierFactory( StreamVerifierAttributes attributes
+ , PGPPublicKeyRingCollection publicKeyRing
+ )
+ throws StreamVerifierException
+ {
+ super( attributes );
+ this.trustedPublicKeyRing = publicKeyRing;
+ }
+ //--------------------------------------------------------------------------------------------
+ public PgpStreamVerifierFactory( StreamVerifierAttributes attributes
+ , InputStream secretKeyRingStream
+ , String secretKeyId
+ , String secretKeyPass
+ )
+ throws StreamVerifierException
+ {
+ super( attributes );
+ init( secretKeyRingStream, secretKeyId, secretKeyPass );
+ }
+ //--------------------------------------------------------------------------------------------
+ public void init( InputStream trustedPublicKeyRingStream )
+ throws StreamVerifierException
+ {
+ try
+ {
+ if( trustedPublicKeyRingStream != null )
+ {
+ trustedPublicKeyRing = new PGPPublicKeyRingCollection(PGPUtil.getDecoderStream(trustedPublicKeyRingStream));
+ if( trustedPublicKeyRing == null )
+ throw new StreamVerifierException( LANG.getMessage( "bad.factory.init.verify.empty" ) );
+ }
+ else
+ throw new StreamVerifierException( LANG.getMessage( "bad.factory.init.verify" ) );
+ }
+ catch( Exception e )
+ {
+ throw new StreamVerifierException(e);
+ }
+ }
+ //--------------------------------------------------------------------------------------------
+ public void init( InputStream secretKeyRingStream
+ , String secretKeyId
+ , String secretKeyPass
+ )
+ throws StreamVerifierException
+ {
+ try
+ {
+ if( secretKeyRingStream != null && secretKeyId != null && secretKeyPass != null )
+ {
+ PGPSecretKeyRing secRing = PgpHelper.readKeyRing( secretKeyRingStream, secretKeyId );
+ PGPSecretKey secKey = secRing.getSecretKey( PgpHelper.hexToId( secretKeyId ) );
+ privateKey = secKey.extractPrivateKey( secretKeyPass.toCharArray(), PgpHelper.PROVIDER );
+ algorithm = secKey.getPublicKey().getAlgorithm();
+ }
+ else
+ throw new StreamVerifierException( LANG.getMessage( "bad.factory.init.generate" ) );
+ }
+ catch( Exception e )
+ {
+ throw new StreamVerifierException(e);
+ }
+ }
+ //--------------------------------------------------------------------------------------------
+ public String getDefaultExtension()
+ {
+ return DEFAULT_EXTENSION;
+ }
+ //--------------------------------------------------------------------------------------------
+ public StreamVerifier newInstance()
+ throws StreamVerifierException
+ {
+ PgpStreamVerifier sv = new PgpStreamVerifier( attributes );
+
+ if( privateKey != null )
+ sv.init( privateKey, algorithm, digestAlgorithm );
+
+ if( trustedPublicKeyRing != null )
+ sv.init( trustedPublicKeyRing );
+
+ return sv;
+ }
+ //--------------------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------------------
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/PgpStreamVerifierFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/pgp/PgpStreamVerifierFactory.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA1Verifier.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA1Verifier.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA1Verifier.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA1Verifier.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,130 @@
+/**
+ * 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.maven.mercury.crypto.sha;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+import org.apache.maven.mercury.crypto.api.AbstractStreamVerifier;
+import org.apache.maven.mercury.crypto.api.StreamVerifier;
+import org.apache.maven.mercury.crypto.api.StreamVerifierAttributes;
+import org.apache.maven.mercury.crypto.api.StreamVerifierException;
+import org.apache.maven.mercury.crypto.basic.ChecksumCalculator;
+
+
+/**
+ * SHA1Verifier
+ *
+ *
+ */
+public class SHA1Verifier
+extends AbstractStreamVerifier
+implements StreamVerifier
+{
+ public static final String digestAlgorithm = "SHA-1";
+
+ private MessageDigest digest;
+ private byte[] digestBytes;
+ private long length = -1;
+ private String lastModified;
+
+ private String sig;
+
+ public SHA1Verifier( StreamVerifierAttributes attributes )
+ {
+ super( attributes );
+
+ try
+ {
+ digest = MessageDigest.getInstance( digestAlgorithm );
+ }
+ catch (NoSuchAlgorithmException e)
+ {
+ //TODO
+ }
+ }
+
+ private byte[] getSignatureBytes ()
+ {
+ if (digestBytes == null)
+ digestBytes = digest.digest();
+ return digestBytes;
+ }
+
+ public String getSignature()
+ {
+ return ChecksumCalculator.encodeToAsciiHex( getSignatureBytes() );
+ }
+
+ public void initSignature( String signatureString )
+ throws StreamVerifierException
+ {
+ if( signatureString == null || signatureString.length() < 1 )
+ throw new IllegalArgumentException("null signature stream");
+
+ sig = signatureString;
+
+ }
+
+ public boolean verifySignature()
+ {
+ String calculatedSignature = getSignature();
+
+ if (calculatedSignature == null && sig == null)
+ return true;
+
+ if ((calculatedSignature != null) && calculatedSignature.equals(sig))
+ return true;
+
+ return false;
+ }
+
+ public void byteReady(int b)
+ {
+ if (digest != null)
+ digest.update((byte)b);
+ }
+
+ public void bytesReady(byte[] b, int off, int len)
+ {
+ if (digest != null)
+ digest.update(b, off, len);
+ }
+ //-----------------------------------------------------------------------------------
+ public long getLength()
+ {
+ return length;
+ }
+ //-----------------------------------------------------------------------------------
+ public void setLength(long length)
+ {
+ this.length = length;
+ }
+
+ public String getLastModified()
+ {
+ return lastModified;
+ }
+
+ public void setLastModified(String time)
+ {
+ lastModified = time;
+ }
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA1Verifier.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA1Verifier.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA1VerifierFactory.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA1VerifierFactory.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA1VerifierFactory.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA1VerifierFactory.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,53 @@
+/**
+ * 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.maven.mercury.crypto.sha;
+
+import org.apache.maven.mercury.crypto.api.AbstractStreamVerifierFactory;
+import org.apache.maven.mercury.crypto.api.StreamVerifier;
+import org.apache.maven.mercury.crypto.api.StreamVerifierAttributes;
+import org.apache.maven.mercury.crypto.api.StreamVerifierFactory;
+
+public class SHA1VerifierFactory
+extends AbstractStreamVerifierFactory
+implements StreamVerifierFactory
+{
+ public static final String DEFAULT_EXTENSION = "sha1";
+
+ public SHA1VerifierFactory( StreamVerifierAttributes attrs )
+ {
+ super( attrs );
+ }
+
+ public SHA1VerifierFactory( boolean lenient, boolean satisfactory )
+ {
+ super( new StreamVerifierAttributes( DEFAULT_EXTENSION, lenient, satisfactory ) );
+ }
+
+ public StreamVerifier newInstance()
+ {
+ return new SHA1Verifier( attributes );
+ }
+
+ public String getDefaultExtension()
+ {
+ return DEFAULT_EXTENSION;
+ }
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA1VerifierFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/crypto/sha/SHA1VerifierFactory.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/AbstractMercuryEvent.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/AbstractMercuryEvent.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/AbstractMercuryEvent.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/AbstractMercuryEvent.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,156 @@
+/**
+ * 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.maven.mercury.event;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public abstract class AbstractMercuryEvent
+implements MercuryEvent
+{
+ EventTypeEnum _type;
+
+ String _name;
+
+ String _tag;
+
+ String _info;
+
+ String _result;
+
+ long _start;
+
+ long _duration;
+
+ Map<String, Object> _payload;
+
+ public AbstractMercuryEvent()
+ {
+ start();
+ }
+
+ public AbstractMercuryEvent( EventTypeEnum type, String name )
+ {
+ this();
+ this._type = type;
+ this._name = name;
+ }
+
+ public AbstractMercuryEvent( EventTypeEnum type, String name, String info )
+ {
+ this( type, name );
+ this._info = info;
+ }
+
+ public long getDuration()
+ {
+ return _duration;
+ }
+
+ public Map<String, Object> getPayload()
+ {
+ return null;
+ }
+
+ public long getStart()
+ {
+ return _start;
+ }
+
+ public EventTypeEnum getType()
+ {
+ return _type;
+ }
+
+ public String getName()
+ {
+ return _name;
+ }
+
+ public String getInfo()
+ {
+ return _info;
+ }
+
+ public String getTag()
+ {
+ return _tag;
+ }
+
+ public String getResult()
+ {
+ return _result;
+ }
+
+ public void setResult( String result )
+ {
+ this._result = result;
+ }
+
+ public void setTag( String tag )
+ {
+ this._tag = tag;
+ }
+
+ public void setInfo( String info )
+ {
+ this._info = info;
+ }
+
+ public boolean hasResult()
+ {
+ return _result != null;
+ }
+
+ public Object getPayload( String name )
+ {
+ return _payload == null ? null : _payload.get( name );
+ }
+
+ public void setPayload( Map<String, Object> payload )
+ {
+ this._payload = payload;
+ }
+
+ public void setPayload( String name, Object value )
+ {
+ if( _payload == null )
+ _payload = new HashMap<String, Object>(4);
+
+ _payload.put( name, value );
+ }
+
+ public void start()
+ {
+ this._start = System.currentTimeMillis();
+ }
+
+ public void stop()
+ {
+ _duration = System.currentTimeMillis() - _start;
+ }
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/AbstractMercuryEvent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/AbstractMercuryEvent.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/DumbListener.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/DumbListener.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/DumbListener.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/DumbListener.java Wed Apr 22 22:56:48 2009
@@ -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.maven.mercury.event;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+
+import org.apache.maven.mercury.event.MercuryEvent.EventMask;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class DumbListener
+implements MercuryEventListener
+{
+
+ Writer wr;
+
+ public DumbListener()
+ {
+ this( System.out );
+ }
+
+ public DumbListener( OutputStream os )
+ {
+ wr = new OutputStreamWriter( os );
+ }
+
+ public void fire( MercuryEvent event )
+ {
+ try
+ {
+ wr.write( "mercury event: "+EventManager.toString( event )+"\n" );
+ wr.flush();
+ }
+ catch( IOException e )
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public EventMask getMask()
+ {
+ return null;
+ }
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/DumbListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/DumbListener.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/EventGenerator.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/EventGenerator.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/EventGenerator.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/EventGenerator.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,52 @@
+/**
+ * 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.maven.mercury.event;
+
+/**
+ *
+ * this component generates events
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public interface EventGenerator
+{
+ /**
+ * register event listener
+ *
+ * @param listener
+ */
+ void register( MercuryEventListener listener );
+
+ /**
+ * remove particular event listener
+ *
+ * @param listener
+ */
+ void unRegister( MercuryEventListener listener );
+
+ /**
+ * set entire event manager
+ *
+ * @param eventManager
+ */
+ void setEventManager( EventManager eventManager );
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/EventGenerator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/EventGenerator.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/EventManager.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/EventManager.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/EventManager.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/EventManager.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,208 @@
+/**
+ * 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.maven.mercury.event;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import org.apache.maven.mercury.logging.IMercuryLogger;
+import org.apache.maven.mercury.logging.MercuryLoggerManager;
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
+
+/**
+ * event queue dispatcher. It registers/unregisters listeners, dispatches events
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class EventManager
+{
+ public static final int THREAD_COUNT = 4;
+
+ /**
+ * this property may contain comma separated list of bit numbers defined in MercuryEvent.EventTypeEnum. It supersedes
+ * any bits set by the appropriate EventManager constructor by OR operation with those
+ */
+ public static final String SYSTEM_PROPERTY_EVENT_MASK = "maven.mercury.events";
+ public static final String systemPropertyEventMask = System.getProperty( SYSTEM_PROPERTY_EVENT_MASK, null );
+
+ private static final IMercuryLogger LOG = MercuryLoggerManager.getLogger( EventManager.class );
+ private static final Language LANG = new DefaultLanguage( EventManager.class );
+
+ final List<MercuryEventListener> _listeners = new ArrayList<MercuryEventListener>(8);
+
+ final LinkedBlockingQueue<UnitOfWork> _queue = new LinkedBlockingQueue<UnitOfWork>( 512 );
+
+ private ExecutorService _execService;
+
+ private MercuryEvent.EventMask _eventMask;
+
+ /**
+ * default initialization - create thread pool
+ */
+ public EventManager()
+ {
+ _execService = Executors.newFixedThreadPool( THREAD_COUNT );
+
+ for( int i = 0; i < THREAD_COUNT; i++ )
+ _execService.execute( new Runner( _queue ) );
+
+ processSystemOptions();
+ }
+
+ /**
+ * default initialization - create thread pool
+ */
+ public EventManager( MercuryEvent.EventMask eventMask )
+ {
+ this();
+
+ this._eventMask = eventMask;
+
+ processSystemOptions();
+ }
+
+ private final void processSystemOptions()
+ {
+ if( systemPropertyEventMask == null )
+ return;
+
+ if( _eventMask == null )
+ _eventMask = new MercuryEvent.EventMask( systemPropertyEventMask );
+ else
+ _eventMask.setBits( systemPropertyEventMask );
+ }
+
+ /**
+ * add listener only if it meets the criteria
+ *
+ * @param listener
+ */
+ public void register( MercuryEventListener listener )
+ {
+ MercuryEvent.EventMask lMask = listener.getMask();
+
+ if( lMask == null || _eventMask == null || _eventMask.intersects( lMask ) )
+ _listeners.add( listener );
+ }
+
+ public void unRegister( MercuryEventListener listener )
+ {
+ _listeners.remove( listener );
+ }
+
+ public List<MercuryEventListener> getListeners()
+ {
+ return _listeners;
+ }
+
+ public void fireEvent( MercuryEvent event )
+ {
+ for( MercuryEventListener listener : _listeners )
+ _queue.add( new UnitOfWork( listener, event ) );
+ }
+
+ public static final String toString( MercuryEvent event )
+ {
+ return new Date( event.getStart() )+", dur: "+ event.getDuration()+" millis :"
+ + " ["+ event.getType()+":"+event.getName()+"] "
+ + ( isEmpty( event.getTag() ) ? "" : ", tag: "+event.getTag() )
+ + ( isEmpty( event.getInfo() ) ? "" : ", info: "+event.getInfo() )
+ + ( isEmpty( event.getResult() ) ? "" : ", result: "+event.getResult() )
+ ;
+ }
+
+ public static final boolean isEmpty( String o )
+ {
+ return o == null || o.length() < 1;
+ }
+
+
+ class UnitOfWork
+ {
+ MercuryEventListener listener;
+ MercuryEvent event;
+
+ public UnitOfWork( MercuryEventListener listener, MercuryEvent event )
+ {
+ this.listener = listener;
+ this.event = event;
+ }
+
+ void execute()
+ {
+ try
+ {
+ MercuryEvent.EventMask lMask = listener.getMask();
+
+ if( _eventMask != null )
+ {
+ if( lMask == null )
+ lMask = _eventMask;
+ else
+ lMask.and( _eventMask );
+ }
+
+
+ if( lMask == null || lMask.get( event.getType().bitNo ) )
+ listener.fire( event );
+ }
+ catch( Throwable th )
+ {
+ LOG.error( LANG.getMessage( "listener.error", th.getMessage() ) );
+ }
+ }
+ }
+
+ class Runner
+ implements Runnable
+ {
+ final LinkedBlockingQueue<UnitOfWork> queue;
+
+ public Runner( LinkedBlockingQueue<UnitOfWork> queue )
+ {
+ this.queue = queue;
+ }
+
+ public void run()
+ {
+ UnitOfWork uow;
+
+ for(;;)
+ try
+ {
+ uow = queue.take();
+ uow.execute();
+ }
+ catch( InterruptedException e )
+ {
+ return;
+ }
+ }
+
+ }
+
+}
+
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/EventManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/EventManager.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/EventTypeEnum.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/EventTypeEnum.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/EventTypeEnum.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/EventTypeEnum.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,53 @@
+/**
+ * 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.maven.mercury.event;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public enum EventTypeEnum
+{
+ dependencyBuilder(0)
+ , satSolver(1)
+
+ , virtualRepositoryReader(2)
+
+ , localRepository(3)
+ , localRepositoryReader(4)
+ , localRepositoryWriter(5)
+
+ , remoteRepository(6)
+ , remoteRepositoryReader(7)
+ , remoteRepositoryWriter(8)
+
+ , cache(9)
+ , fsCache(10)
+ ;
+
+ int bitNo;
+
+ EventTypeEnum( int bitNo )
+ {
+ this.bitNo = bitNo;
+ }
+ }
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/EventTypeEnum.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/EventTypeEnum.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/GenericEvent.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/GenericEvent.java?rev=767705&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/GenericEvent.java (added)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/GenericEvent.java Wed Apr 22 22:56:48 2009
@@ -0,0 +1,42 @@
+/**
+ * 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.maven.mercury.event;
+
+/**
+ *
+ *
+ * @author Oleg Gusakov
+ * @version $Id$
+ *
+ */
+public class GenericEvent
+extends AbstractMercuryEvent
+{
+
+ public GenericEvent( EventTypeEnum type, String name )
+ {
+ super(type, name);
+ }
+
+ public GenericEvent( EventTypeEnum type, String name, String tag )
+ {
+ super( type, name, tag );
+ }
+
+}
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/GenericEvent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/event/GenericEvent.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision