http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/repository/AuthenticationBuilder.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/repository/AuthenticationBuilder.java b/aether-util/src/main/java/org/eclipse/aether/util/repository/AuthenticationBuilder.java deleted file mode 100644 index bc69e85..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/repository/AuthenticationBuilder.java +++ /dev/null @@ -1,231 +0,0 @@ -package org.eclipse.aether.util.repository; - -/* - * 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. - */ - -import java.util.ArrayList; -import java.util.List; - -import javax.net.ssl.HostnameVerifier; - -import org.eclipse.aether.repository.Authentication; -import org.eclipse.aether.repository.AuthenticationContext; - -/** - * A utility class to build authentication info for repositories and proxies. - */ -public final class AuthenticationBuilder -{ - - private final List<Authentication> authentications; - - /** - * Creates a new authentication builder. - */ - public AuthenticationBuilder() - { - authentications = new ArrayList<Authentication>(); - } - - /** - * Builds a new authentication object from the current data of this builder. The state of the builder itself remains - * unchanged. - * - * @return The authentication or {@code null} if no authentication data was supplied to the builder. - */ - public Authentication build() - { - if ( authentications.isEmpty() ) - { - return null; - } - if ( authentications.size() == 1 ) - { - return authentications.get( 0 ); - } - return new ChainedAuthentication( authentications ); - } - - /** - * Adds username data to the authentication. - * - * @param username The username, may be {@code null}. - * @return This builder for chaining, never {@code null}. - */ - public AuthenticationBuilder addUsername( String username ) - { - return addString( AuthenticationContext.USERNAME, username ); - } - - /** - * Adds password data to the authentication. - * - * @param password The password, may be {@code null}. - * @return This builder for chaining, never {@code null}. - */ - public AuthenticationBuilder addPassword( String password ) - { - return addSecret( AuthenticationContext.PASSWORD, password ); - } - - /** - * Adds password data to the authentication. The resulting authentication object uses an encrypted copy of the - * supplied character data and callers are advised to clear the input array soon after this method returns. - * - * @param password The password, may be {@code null}. - * @return This builder for chaining, never {@code null}. - */ - public AuthenticationBuilder addPassword( char[] password ) - { - return addSecret( AuthenticationContext.PASSWORD, password ); - } - - /** - * Adds NTLM data to the authentication. - * - * @param workstation The NTLM workstation name, may be {@code null}. - * @param domain The NTLM domain name, may be {@code null}. - * @return This builder for chaining, never {@code null}. - */ - public AuthenticationBuilder addNtlm( String workstation, String domain ) - { - addString( AuthenticationContext.NTLM_WORKSTATION, workstation ); - return addString( AuthenticationContext.NTLM_DOMAIN, domain ); - } - - /** - * Adds private key data to the authentication. - * - * @param pathname The (absolute) path to the private key file, may be {@code null}. - * @param passphrase The passphrase protecting the private key, may be {@code null}. - * @return This builder for chaining, never {@code null}. - */ - public AuthenticationBuilder addPrivateKey( String pathname, String passphrase ) - { - if ( pathname != null ) - { - addString( AuthenticationContext.PRIVATE_KEY_PATH, pathname ); - addSecret( AuthenticationContext.PRIVATE_KEY_PASSPHRASE, passphrase ); - } - return this; - } - - /** - * Adds private key data to the authentication. The resulting authentication object uses an encrypted copy of the - * supplied character data and callers are advised to clear the input array soon after this method returns. - * - * @param pathname The (absolute) path to the private key file, may be {@code null}. - * @param passphrase The passphrase protecting the private key, may be {@code null}. - * @return This builder for chaining, never {@code null}. - */ - public AuthenticationBuilder addPrivateKey( String pathname, char[] passphrase ) - { - if ( pathname != null ) - { - addString( AuthenticationContext.PRIVATE_KEY_PATH, pathname ); - addSecret( AuthenticationContext.PRIVATE_KEY_PASSPHRASE, passphrase ); - } - return this; - } - - /** - * Adds a hostname verifier for SSL. <strong>Note:</strong> This method assumes that all possible instances of the - * verifier's runtime type exhibit the exact same behavior, i.e. the behavior of the verifier depends solely on the - * runtime type and not on any configuration. For verifiers that do not fit this assumption, use - * {@link #addCustom(Authentication)} with a suitable implementation instead. - * - * @param verifier The hostname verifier, may be {@code null}. - * @return This builder for chaining, never {@code null}. - */ - public AuthenticationBuilder addHostnameVerifier( HostnameVerifier verifier ) - { - if ( verifier != null ) - { - authentications.add( new ComponentAuthentication( AuthenticationContext.SSL_HOSTNAME_VERIFIER, verifier ) ); - } - return this; - } - - /** - * Adds custom string data to the authentication. <em>Note:</em> If the string data is confidential, use - * {@link #addSecret(String, char[])} instead. - * - * @param key The key for the authentication data, must not be {@code null}. - * @param value The value for the authentication data, may be {@code null}. - * @return This builder for chaining, never {@code null}. - */ - public AuthenticationBuilder addString( String key, String value ) - { - if ( value != null ) - { - authentications.add( new StringAuthentication( key, value ) ); - } - return this; - } - - /** - * Adds sensitive custom string data to the authentication. - * - * @param key The key for the authentication data, must not be {@code null}. - * @param value The value for the authentication data, may be {@code null}. - * @return This builder for chaining, never {@code null}. - */ - public AuthenticationBuilder addSecret( String key, String value ) - { - if ( value != null ) - { - authentications.add( new SecretAuthentication( key, value ) ); - } - return this; - } - - /** - * Adds sensitive custom string data to the authentication. The resulting authentication object uses an encrypted - * copy of the supplied character data and callers are advised to clear the input array soon after this method - * returns. - * - * @param key The key for the authentication data, must not be {@code null}. - * @param value The value for the authentication data, may be {@code null}. - * @return This builder for chaining, never {@code null}. - */ - public AuthenticationBuilder addSecret( String key, char[] value ) - { - if ( value != null ) - { - authentications.add( new SecretAuthentication( key, value ) ); - } - return this; - } - - /** - * Adds custom authentication data to the authentication. - * - * @param authentication The authentication to add, may be {@code null}. - * @return This builder for chaining, never {@code null}. - */ - public AuthenticationBuilder addCustom( Authentication authentication ) - { - if ( authentication != null ) - { - authentications.add( authentication ); - } - return this; - } - -}
http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/repository/ChainedAuthentication.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/repository/ChainedAuthentication.java b/aether-util/src/main/java/org/eclipse/aether/util/repository/ChainedAuthentication.java deleted file mode 100644 index 40dae3f..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/repository/ChainedAuthentication.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.eclipse.aether.util.repository; - -/* - * 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. - */ - -import java.util.Arrays; -import java.util.Collection; -import java.util.Map; - -import org.eclipse.aether.repository.Authentication; -import org.eclipse.aether.repository.AuthenticationContext; -import org.eclipse.aether.repository.AuthenticationDigest; - -/** - * Authentication that aggregates other authentication blocks. When multiple input authentication blocks provide the - * same authentication key, the last written value wins. - */ -final class ChainedAuthentication - implements Authentication -{ - - private final Authentication[] authentications; - - public ChainedAuthentication( Authentication... authentications ) - { - if ( authentications != null && authentications.length > 0 ) - { - this.authentications = authentications.clone(); - } - else - { - this.authentications = new Authentication[0]; - } - } - - public ChainedAuthentication( Collection<? extends Authentication> authentications ) - { - if ( authentications != null && !authentications.isEmpty() ) - { - this.authentications = authentications.toArray( new Authentication[authentications.size()] ); - } - else - { - this.authentications = new Authentication[0]; - } - } - - public void fill( AuthenticationContext context, String key, Map<String, String> data ) - { - for ( Authentication authentication : authentications ) - { - authentication.fill( context, key, data ); - } - } - - public void digest( AuthenticationDigest digest ) - { - for ( Authentication authentication : authentications ) - { - authentication.digest( digest ); - } - } - - @Override - public boolean equals( Object obj ) - { - if ( this == obj ) - { - return true; - } - if ( obj == null || !getClass().equals( obj.getClass() ) ) - { - return false; - } - ChainedAuthentication that = (ChainedAuthentication) obj; - return Arrays.equals( authentications, that.authentications ); - } - - @Override - public int hashCode() - { - return Arrays.hashCode( authentications ); - } - - @Override - public String toString() - { - StringBuilder buffer = new StringBuilder( 256 ); - for ( Authentication authentication : authentications ) - { - if ( buffer.length() > 0 ) - { - buffer.append( ", " ); - } - buffer.append( authentication ); - } - return buffer.toString(); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/repository/ChainedWorkspaceReader.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/repository/ChainedWorkspaceReader.java b/aether-util/src/main/java/org/eclipse/aether/util/repository/ChainedWorkspaceReader.java deleted file mode 100644 index 0a9b8f6..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/repository/ChainedWorkspaceReader.java +++ /dev/null @@ -1,164 +0,0 @@ -package org.eclipse.aether.util.repository; - -/* - * 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. - */ - -import java.io.File; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.List; - -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.repository.WorkspaceReader; -import org.eclipse.aether.repository.WorkspaceRepository; - -/** - * A workspace reader that delegates to a chain of other readers, effectively aggregating their contents. - */ -public final class ChainedWorkspaceReader - implements WorkspaceReader -{ - - private List<WorkspaceReader> readers = new ArrayList<WorkspaceReader>(); - - private WorkspaceRepository repository; - - /** - * Creates a new workspace reader by chaining the specified readers. - * - * @param readers The readers to chain, may be {@code null}. - * @see #newInstance(WorkspaceReader, WorkspaceReader) - */ - public ChainedWorkspaceReader( WorkspaceReader... readers ) - { - if ( readers != null ) - { - Collections.addAll( this.readers, readers ); - } - - StringBuilder buffer = new StringBuilder(); - for ( WorkspaceReader reader : this.readers ) - { - if ( buffer.length() > 0 ) - { - buffer.append( '+' ); - } - buffer.append( reader.getRepository().getContentType() ); - } - - repository = new WorkspaceRepository( buffer.toString(), new Key( this.readers ) ); - } - - /** - * Creates a new workspace reader by chaining the specified readers. In contrast to the constructor, this factory - * method will avoid creating an actual chained reader if one of the specified readers is actually {@code null}. - * - * @param reader1 The first workspace reader, may be {@code null}. - * @param reader2 The second workspace reader, may be {@code null}. - * @return The chained reader or {@code null} if no workspace reader was supplied. - */ - public static WorkspaceReader newInstance( WorkspaceReader reader1, WorkspaceReader reader2 ) - { - if ( reader1 == null ) - { - return reader2; - } - else if ( reader2 == null ) - { - return reader1; - } - return new ChainedWorkspaceReader( reader1, reader2 ); - } - - public File findArtifact( Artifact artifact ) - { - File file = null; - - for ( WorkspaceReader reader : readers ) - { - file = reader.findArtifact( artifact ); - if ( file != null ) - { - break; - } - } - - return file; - } - - public List<String> findVersions( Artifact artifact ) - { - Collection<String> versions = new LinkedHashSet<String>(); - - for ( WorkspaceReader reader : readers ) - { - versions.addAll( reader.findVersions( artifact ) ); - } - - return Collections.unmodifiableList( new ArrayList<String>( versions ) ); - } - - public WorkspaceRepository getRepository() - { - Key key = new Key( readers ); - if ( !key.equals( repository.getKey() ) ) - { - repository = new WorkspaceRepository( repository.getContentType(), key ); - } - return repository; - } - - private static class Key - { - - private final List<Object> keys = new ArrayList<Object>(); - - public Key( List<WorkspaceReader> readers ) - { - for ( WorkspaceReader reader : readers ) - { - keys.add( reader.getRepository().getKey() ); - } - } - - @Override - public boolean equals( Object obj ) - { - if ( this == obj ) - { - return true; - } - if ( obj == null || !getClass().equals( obj.getClass() ) ) - { - return false; - } - return keys.equals( ( (Key) obj ).keys ); - } - - @Override - public int hashCode() - { - return keys.hashCode(); - } - - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/repository/ComponentAuthentication.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/repository/ComponentAuthentication.java b/aether-util/src/main/java/org/eclipse/aether/util/repository/ComponentAuthentication.java deleted file mode 100644 index af83c9d..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/repository/ComponentAuthentication.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.eclipse.aether.util.repository; - -/* - * 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. - */ - -import java.util.Map; - -import org.eclipse.aether.repository.Authentication; -import org.eclipse.aether.repository.AuthenticationContext; -import org.eclipse.aether.repository.AuthenticationDigest; - -/** - * Authentication block that manages a single authentication key and its component value. In this context, component - * refers to an object whose behavior is solely dependent on its implementation class. - */ -final class ComponentAuthentication - implements Authentication -{ - - private final String key; - - private final Object value; - - public ComponentAuthentication( String key, Object value ) - { - if ( key == null ) - { - throw new IllegalArgumentException( "authentication key missing" ); - } - this.key = key; - this.value = value; - } - - public void fill( AuthenticationContext context, String key, Map<String, String> data ) - { - context.put( this.key, value ); - } - - public void digest( AuthenticationDigest digest ) - { - if ( value != null ) - { - digest.update( key, value.getClass().getName() ); - } - } - - @Override - public boolean equals( Object obj ) - { - if ( this == obj ) - { - return true; - } - if ( obj == null || !getClass().equals( obj.getClass() ) ) - { - return false; - } - ComponentAuthentication that = (ComponentAuthentication) obj; - return key.equals( that.key ) && eqClass( value, that.value ); - } - - private static <T> boolean eqClass( T s1, T s2 ) - { - return ( s1 == null ) ? s2 == null : s2 != null && s1.getClass().equals( s2.getClass() ); - } - - @Override - public int hashCode() - { - int hash = 17; - hash = hash * 31 + key.hashCode(); - hash = hash * 31 + ( ( value != null ) ? value.getClass().hashCode() : 0 ); - return hash; - } - - @Override - public String toString() - { - return key + "=" + value; - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/repository/ConservativeAuthenticationSelector.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/repository/ConservativeAuthenticationSelector.java b/aether-util/src/main/java/org/eclipse/aether/util/repository/ConservativeAuthenticationSelector.java deleted file mode 100644 index 6e727e5..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/repository/ConservativeAuthenticationSelector.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.eclipse.aether.util.repository; - -/* - * 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. - */ - -import org.eclipse.aether.repository.Authentication; -import org.eclipse.aether.repository.AuthenticationSelector; -import org.eclipse.aether.repository.RemoteRepository; - -/** - * An authentication selector that delegates to another selector but only if a repository has no authentication data - * yet. If authentication has already been assigned to a repository, that is selected. - */ -public final class ConservativeAuthenticationSelector - implements AuthenticationSelector -{ - - private final AuthenticationSelector selector; - - /** - * Creates a new selector that delegates to the specified selector. - * - * @param selector The selector to delegate to in case a repository has no authentication yet, must not be - * {@code null}. - */ - public ConservativeAuthenticationSelector( AuthenticationSelector selector ) - { - if ( selector == null ) - { - throw new IllegalArgumentException( "no authentication selector specified" ); - } - this.selector = selector; - } - - public Authentication getAuthentication( RemoteRepository repository ) - { - Authentication auth = repository.getAuthentication(); - if ( auth != null ) - { - return auth; - } - return selector.getAuthentication( repository ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/repository/ConservativeProxySelector.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/repository/ConservativeProxySelector.java b/aether-util/src/main/java/org/eclipse/aether/util/repository/ConservativeProxySelector.java deleted file mode 100644 index 437c719..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/repository/ConservativeProxySelector.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.eclipse.aether.util.repository; - -/* - * 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. - */ - -import org.eclipse.aether.repository.Proxy; -import org.eclipse.aether.repository.ProxySelector; -import org.eclipse.aether.repository.RemoteRepository; - -/** - * A proxy selector that delegates to another selector but only if a repository has no proxy yet. If a proxy has already - * been assigned to a repository, that is selected. - */ -public final class ConservativeProxySelector - implements ProxySelector -{ - - private final ProxySelector selector; - - /** - * Creates a new selector that delegates to the specified selector. - * - * @param selector The selector to delegate to in case a repository has no proxy yet, must not be {@code null}. - */ - public ConservativeProxySelector( ProxySelector selector ) - { - if ( selector == null ) - { - throw new IllegalArgumentException( "no proxy selector specified" ); - } - this.selector = selector; - } - - public Proxy getProxy( RemoteRepository repository ) - { - Proxy proxy = repository.getProxy(); - if ( proxy != null ) - { - return proxy; - } - return selector.getProxy( repository ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultAuthenticationSelector.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultAuthenticationSelector.java b/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultAuthenticationSelector.java deleted file mode 100644 index a5d4ce3..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultAuthenticationSelector.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.eclipse.aether.util.repository; - -/* - * 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. - */ - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.aether.repository.Authentication; -import org.eclipse.aether.repository.AuthenticationSelector; -import org.eclipse.aether.repository.RemoteRepository; - -/** - * A simple authentication selector that selects authentication based on repository identifiers. - */ -public final class DefaultAuthenticationSelector - implements AuthenticationSelector -{ - - private final Map<String, Authentication> repos = new HashMap<String, Authentication>(); - - /** - * Adds the specified authentication info for the given repository identifier. - * - * @param id The identifier of the repository to add the authentication for, must not be {@code null}. - * @param auth The authentication to add, may be {@code null}. - * @return This selector for chaining, never {@code null}. - */ - public DefaultAuthenticationSelector add( String id, Authentication auth ) - { - if ( auth != null ) - { - repos.put( id, auth ); - } - else - { - repos.remove( id ); - } - - return this; - } - - public Authentication getAuthentication( RemoteRepository repository ) - { - return repos.get( repository.getId() ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultMirrorSelector.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultMirrorSelector.java b/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultMirrorSelector.java deleted file mode 100644 index 71b3da4..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultMirrorSelector.java +++ /dev/null @@ -1,273 +0,0 @@ -package org.eclipse.aether.util.repository; - -/* - * 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. - */ - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import org.eclipse.aether.repository.MirrorSelector; -import org.eclipse.aether.repository.RemoteRepository; - -/** - * A simple mirror selector that selects mirrors based on repository identifiers. - */ -public final class DefaultMirrorSelector - implements MirrorSelector -{ - - private static final String WILDCARD = "*"; - - private static final String EXTERNAL_WILDCARD = "external:*"; - - private final List<MirrorDef> mirrors = new ArrayList<MirrorDef>(); - - /** - * Adds the specified mirror to this selector. - * - * @param id The identifier of the mirror, must not be {@code null}. - * @param url The URL of the mirror, must not be {@code null}. - * @param type The content type of the mirror, must not be {@code null}. - * @param repositoryManager A flag whether the mirror is a repository manager or a simple server. - * @param mirrorOfIds The identifier(s) of remote repositories to mirror, must not be {@code null}. Multiple - * identifiers can be separated by comma and additionally the wildcards "*" and "external:*" can be used - * to match all (external) repositories, prefixing a repo id with an exclamation mark allows to express - * an exclusion. For example "external:*,!central". - * @param mirrorOfTypes The content type(s) of remote repositories to mirror, may be {@code null} or empty to match - * any content type. Similar to the repo id specification, multiple types can be comma-separated, the - * wildcard "*" and the "!" negation syntax are supported. For example "*,!p2". - * @return This selector for chaining, never {@code null}. - */ - public DefaultMirrorSelector add( String id, String url, String type, boolean repositoryManager, - String mirrorOfIds, String mirrorOfTypes ) - { - mirrors.add( new MirrorDef( id, url, type, repositoryManager, mirrorOfIds, mirrorOfTypes ) ); - - return this; - } - - public RemoteRepository getMirror( RemoteRepository repository ) - { - MirrorDef mirror = findMirror( repository ); - - if ( mirror == null ) - { - return null; - } - - RemoteRepository.Builder builder = - new RemoteRepository.Builder( mirror.id, repository.getContentType(), mirror.url ); - - builder.setRepositoryManager( mirror.repositoryManager ); - - if ( mirror.type != null && mirror.type.length() > 0 ) - { - builder.setContentType( mirror.type ); - } - - builder.setSnapshotPolicy( repository.getPolicy( true ) ); - builder.setReleasePolicy( repository.getPolicy( false ) ); - - builder.setMirroredRepositories( Collections.singletonList( repository ) ); - - return builder.build(); - } - - private MirrorDef findMirror( RemoteRepository repository ) - { - String repoId = repository.getId(); - - if ( repoId != null && !mirrors.isEmpty() ) - { - for ( MirrorDef mirror : mirrors ) - { - if ( repoId.equals( mirror.mirrorOfIds ) && matchesType( repository.getContentType(), - mirror.mirrorOfTypes ) ) - { - return mirror; - } - } - - for ( MirrorDef mirror : mirrors ) - { - if ( matchPattern( repository, mirror.mirrorOfIds ) && matchesType( repository.getContentType(), - mirror.mirrorOfTypes ) ) - { - return mirror; - } - } - } - - return null; - } - - /** - * This method checks if the pattern matches the originalRepository. Valid patterns: * = everything external:* = - * everything not on the localhost and not file based. repo,repo1 = repo or repo1 *,!repo1 = everything except repo1 - * - * @param repository to compare for a match. - * @param pattern used for match. Currently only '*' is supported. - * @return true if the repository is a match to this pattern. - */ - static boolean matchPattern( RemoteRepository repository, String pattern ) - { - boolean result = false; - String originalId = repository.getId(); - - // simple checks first to short circuit processing below. - if ( WILDCARD.equals( pattern ) || pattern.equals( originalId ) ) - { - result = true; - } - else - { - // process the list - String[] repos = pattern.split( "," ); - for ( String repo : repos ) - { - // see if this is a negative match - if ( repo.length() > 1 && repo.startsWith( "!" ) ) - { - if ( repo.substring( 1 ).equals( originalId ) ) - { - // explicitly exclude. Set result and stop processing. - result = false; - break; - } - } - // check for exact match - else if ( repo.equals( originalId ) ) - { - result = true; - break; - } - // check for external:* - else if ( EXTERNAL_WILDCARD.equals( repo ) && isExternalRepo( repository ) ) - { - result = true; - // don't stop processing in case a future segment explicitly excludes this repo - } - else if ( WILDCARD.equals( repo ) ) - { - result = true; - // don't stop processing in case a future segment explicitly excludes this repo - } - } - } - return result; - } - - /** - * Checks the URL to see if this repository refers to an external repository. - * - * @param repository The repository to check, must not be {@code null}. - * @return {@code true} if external, {@code false} otherwise. - */ - static boolean isExternalRepo( RemoteRepository repository ) - { - boolean local = - "localhost".equals( repository.getHost() ) || "127.0.0.1".equals( repository.getHost() ) - || "file".equalsIgnoreCase( repository.getProtocol() ); - return !local; - } - - /** - * Checks whether the types configured for a mirror match with the type of the repository. - * - * @param repoType The type of the repository, may be {@code null}. - * @param mirrorType The types supported by the mirror, may be {@code null}. - * @return {@code true} if the types associated with the mirror match the type of the original repository, - * {@code false} otherwise. - */ - static boolean matchesType( String repoType, String mirrorType ) - { - boolean result = false; - - // simple checks first to short circuit processing below. - if ( mirrorType == null || mirrorType.length() <= 0 || WILDCARD.equals( mirrorType ) ) - { - result = true; - } - else if ( mirrorType.equals( repoType ) ) - { - result = true; - } - else - { - // process the list - String[] layouts = mirrorType.split( "," ); - for ( String layout : layouts ) - { - // see if this is a negative match - if ( layout.length() > 1 && layout.startsWith( "!" ) ) - { - if ( layout.substring( 1 ).equals( repoType ) ) - { - // explicitly exclude. Set result and stop processing. - result = false; - break; - } - } - // check for exact match - else if ( layout.equals( repoType ) ) - { - result = true; - break; - } - else if ( WILDCARD.equals( layout ) ) - { - result = true; - // don't stop processing in case a future segment explicitly excludes this repo - } - } - } - - return result; - } - - static class MirrorDef - { - - final String id; - - final String url; - - final String type; - - final boolean repositoryManager; - - final String mirrorOfIds; - - final String mirrorOfTypes; - - public MirrorDef( String id, String url, String type, boolean repositoryManager, String mirrorOfIds, - String mirrorOfTypes ) - { - this.id = id; - this.url = url; - this.type = type; - this.repositoryManager = repositoryManager; - this.mirrorOfIds = mirrorOfIds; - this.mirrorOfTypes = mirrorOfTypes; - } - - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultProxySelector.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultProxySelector.java b/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultProxySelector.java deleted file mode 100644 index 3977c6c..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultProxySelector.java +++ /dev/null @@ -1,155 +0,0 @@ -package org.eclipse.aether.util.repository; - -/* - * 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. - */ - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.StringTokenizer; -import java.util.regex.Pattern; - -import org.eclipse.aether.repository.Proxy; -import org.eclipse.aether.repository.ProxySelector; -import org.eclipse.aether.repository.RemoteRepository; - -/** - * A simple proxy selector that selects the first matching proxy from a list of configured proxies. - */ -public final class DefaultProxySelector - implements ProxySelector -{ - - private List<ProxyDef> proxies = new ArrayList<ProxyDef>(); - - /** - * Adds the specified proxy definition to the selector. Proxy definitions are ordered, the first matching proxy for - * a given repository will be used. - * - * @param proxy The proxy definition to add, must not be {@code null}. - * @param nonProxyHosts The list of (case-insensitive) host names to exclude from proxying, may be {@code null}. - * @return This proxy selector for chaining, never {@code null}. - */ - public DefaultProxySelector add( Proxy proxy, String nonProxyHosts ) - { - if ( proxy == null ) - { - throw new IllegalArgumentException( "proxy not specified" ); - } - proxies.add( new ProxyDef( proxy, nonProxyHosts ) ); - - return this; - } - - public Proxy getProxy( RemoteRepository repository ) - { - Map<String, ProxyDef> candidates = new HashMap<String, ProxyDef>(); - - String host = repository.getHost(); - for ( ProxyDef proxy : proxies ) - { - if ( !proxy.nonProxyHosts.isNonProxyHost( host ) ) - { - String key = proxy.proxy.getType().toLowerCase( Locale.ENGLISH ); - if ( !candidates.containsKey( key ) ) - { - candidates.put( key, proxy ); - } - } - } - - String protocol = repository.getProtocol().toLowerCase( Locale.ENGLISH ); - - if ( "davs".equals( protocol ) ) - { - protocol = "https"; - } - else if ( "dav".equals( protocol ) ) - { - protocol = "http"; - } - else if ( protocol.startsWith( "dav:" ) ) - { - protocol = protocol.substring( "dav:".length() ); - } - - ProxyDef proxy = candidates.get( protocol ); - if ( proxy == null && "https".equals( protocol ) ) - { - proxy = candidates.get( "http" ); - } - - return ( proxy != null ) ? proxy.proxy : null; - } - - static class NonProxyHosts - { - - private final Pattern[] patterns; - - public NonProxyHosts( String nonProxyHosts ) - { - List<Pattern> patterns = new ArrayList<Pattern>(); - if ( nonProxyHosts != null ) - { - for ( StringTokenizer tokenizer = new StringTokenizer( nonProxyHosts, "|" ); tokenizer.hasMoreTokens(); ) - { - String pattern = tokenizer.nextToken(); - pattern = pattern.replace( ".", "\\." ).replace( "*", ".*" ); - patterns.add( Pattern.compile( pattern, Pattern.CASE_INSENSITIVE ) ); - } - } - this.patterns = patterns.toArray( new Pattern[patterns.size()] ); - } - - boolean isNonProxyHost( String host ) - { - if ( host != null ) - { - for ( Pattern pattern : patterns ) - { - if ( pattern.matcher( host ).matches() ) - { - return true; - } - } - } - return false; - } - - } - - static class ProxyDef - { - - final Proxy proxy; - - final NonProxyHosts nonProxyHosts; - - public ProxyDef( Proxy proxy, String nonProxyHosts ) - { - this.proxy = proxy; - this.nonProxyHosts = new NonProxyHosts( nonProxyHosts ); - } - - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/repository/JreProxySelector.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/repository/JreProxySelector.java b/aether-util/src/main/java/org/eclipse/aether/util/repository/JreProxySelector.java deleted file mode 100644 index a09b435..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/repository/JreProxySelector.java +++ /dev/null @@ -1,182 +0,0 @@ -package org.eclipse.aether.util.repository; - -/* - * 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. - */ - -import java.net.Authenticator; -import java.net.InetSocketAddress; -import java.net.PasswordAuthentication; -import java.net.SocketAddress; -import java.net.URI; -import java.net.URL; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.eclipse.aether.repository.Authentication; -import org.eclipse.aether.repository.AuthenticationContext; -import org.eclipse.aether.repository.AuthenticationDigest; -import org.eclipse.aether.repository.Proxy; -import org.eclipse.aether.repository.ProxySelector; -import org.eclipse.aether.repository.RemoteRepository; - -/** - * A proxy selector that uses the {@link java.net.ProxySelector#getDefault() JRE's global proxy selector}. In - * combination with the system property {@code java.net.useSystemProxies}, this proxy selector can be employed to pick - * up the proxy configuration from the operating system, see <a - * href="http://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html">Java Networking and Proxies</a> for - * details. The {@link java.net.Authenticator JRE's global authenticator} is used to look up credentials for a proxy - * when needed. - */ -public final class JreProxySelector - implements ProxySelector -{ - - /** - * Creates a new proxy selector that delegates to {@link java.net.ProxySelector#getDefault()}. - */ - public JreProxySelector() - { - } - - public Proxy getProxy( RemoteRepository repository ) - { - List<java.net.Proxy> proxies = null; - try - { - URI uri = new URI( repository.getUrl() ).parseServerAuthority(); - proxies = java.net.ProxySelector.getDefault().select( uri ); - } - catch ( Exception e ) - { - // URL invalid or not accepted by selector or no selector at all, simply use no proxy - } - if ( proxies != null ) - { - for ( java.net.Proxy proxy : proxies ) - { - if ( java.net.Proxy.Type.DIRECT.equals( proxy.type() ) ) - { - break; - } - if ( java.net.Proxy.Type.HTTP.equals( proxy.type() ) && isValid( proxy.address() ) ) - { - InetSocketAddress addr = (InetSocketAddress) proxy.address(); - return new Proxy( Proxy.TYPE_HTTP, addr.getHostName(), addr.getPort(), - JreProxyAuthentication.INSTANCE ); - } - } - } - return null; - } - - private static boolean isValid( SocketAddress address ) - { - if ( address instanceof InetSocketAddress ) - { - /* - * NOTE: On some platforms with java.net.useSystemProxies=true, unconfigured proxies show up as proxy - * objects with empty host and port 0. - */ - InetSocketAddress addr = (InetSocketAddress) address; - if ( addr.getPort() <= 0 ) - { - return false; - } - if ( addr.getHostName() == null || addr.getHostName().length() <= 0 ) - { - return false; - } - return true; - } - return false; - } - - private static final class JreProxyAuthentication - implements Authentication - { - - public static final Authentication INSTANCE = new JreProxyAuthentication(); - - public void fill( AuthenticationContext context, String key, Map<String, String> data ) - { - Proxy proxy = context.getProxy(); - if ( proxy == null ) - { - return; - } - if ( !AuthenticationContext.USERNAME.equals( key ) && !AuthenticationContext.PASSWORD.equals( key ) ) - { - return; - } - - try - { - URL url; - try - { - url = new URL( context.getRepository().getUrl() ); - } - catch ( Exception e ) - { - url = null; - } - - PasswordAuthentication auth = - Authenticator.requestPasswordAuthentication( proxy.getHost(), null, proxy.getPort(), "http", - "Credentials for proxy " + proxy, null, url, - Authenticator.RequestorType.PROXY ); - if ( auth != null ) - { - context.put( AuthenticationContext.USERNAME, auth.getUserName() ); - context.put( AuthenticationContext.PASSWORD, auth.getPassword() ); - } - else - { - context.put( AuthenticationContext.USERNAME, System.getProperty( "http.proxyUser" ) ); - context.put( AuthenticationContext.PASSWORD, System.getProperty( "http.proxyPassword" ) ); - } - } - catch ( SecurityException e ) - { - // oh well, let's hope the proxy can do without auth - } - } - - public void digest( AuthenticationDigest digest ) - { - // we don't know anything about the JRE's current authenticator, assume the worst (i.e. interactive) - digest.update( UUID.randomUUID().toString() ); - } - - @Override - public boolean equals( Object obj ) - { - return this == obj || ( obj != null && getClass().equals( obj.getClass() ) ); - } - - @Override - public int hashCode() - { - return getClass().hashCode(); - } - - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/repository/SecretAuthentication.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/repository/SecretAuthentication.java b/aether-util/src/main/java/org/eclipse/aether/util/repository/SecretAuthentication.java deleted file mode 100644 index 8b3b095..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/repository/SecretAuthentication.java +++ /dev/null @@ -1,181 +0,0 @@ -package org.eclipse.aether.util.repository; - -/* - * 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. - */ - -import java.util.Arrays; -import java.util.Map; - -import org.eclipse.aether.repository.Authentication; -import org.eclipse.aether.repository.AuthenticationContext; -import org.eclipse.aether.repository.AuthenticationDigest; - -/** - * Authentication block that manages a single authentication key and its secret string value (password, passphrase). - * Unlike {@link StringAuthentication}, the string value is kept in an encrypted buffer and only decrypted when needed - * to reduce the potential of leaking the secret in a heap dump. - */ -final class SecretAuthentication - implements Authentication -{ - - private static final Object[] KEYS; - - static - { - KEYS = new Object[16]; - for ( int i = 0; i < KEYS.length; i++ ) - { - KEYS[i] = new Object(); - } - } - - private final String key; - - private final char[] value; - - private final int secretHash; - - public SecretAuthentication( String key, String value ) - { - this( ( value != null ) ? value.toCharArray() : null, key ); - } - - public SecretAuthentication( String key, char[] value ) - { - this( copy( value ), key ); - } - - private SecretAuthentication( char[] value, String key ) - { - if ( key == null ) - { - throw new IllegalArgumentException( "authentication key missing" ); - } - this.key = key; - this.secretHash = Arrays.hashCode( value ) ^ KEYS[0].hashCode(); - this.value = xor( value ); - } - - private static char[] copy( char[] chars ) - { - return ( chars != null ) ? chars.clone() : null; - } - - private char[] xor( char[] chars ) - { - if ( chars != null ) - { - int mask = System.identityHashCode( this ); - for ( int i = 0; i < chars.length; i++ ) - { - int key = KEYS[( i >> 1 ) % KEYS.length].hashCode(); - key ^= mask; - chars[i] ^= ( ( i & 1 ) == 0 ) ? ( key & 0xFFFF ) : ( key >>> 16 ); - } - } - return chars; - } - - private static void clear( char[] chars ) - { - if ( chars != null ) - { - for ( int i = 0; i < chars.length; i++ ) - { - chars[i] = '\0'; - } - } - } - - public void fill( AuthenticationContext context, String key, Map<String, String> data ) - { - char[] secret = copy( value ); - xor( secret ); - context.put( this.key, secret ); - // secret will be cleared upon AuthenticationContext.close() - } - - public void digest( AuthenticationDigest digest ) - { - char[] secret = copy( value ); - try - { - xor( secret ); - digest.update( key ); - digest.update( secret ); - } - finally - { - clear( secret ); - } - } - - @Override - public boolean equals( Object obj ) - { - if ( this == obj ) - { - return true; - } - if ( obj == null || !getClass().equals( obj.getClass() ) ) - { - return false; - } - SecretAuthentication that = (SecretAuthentication) obj; - if ( !eq( key, that.key ) || secretHash != that.secretHash ) - { - return false; - } - char[] secret = copy( value ); - char[] thatSecret = copy( that.value ); - try - { - xor( secret ); - that.xor( thatSecret ); - return Arrays.equals( secret, thatSecret ); - } - finally - { - clear( secret ); - clear( thatSecret ); - } - } - - private static <T> boolean eq( T s1, T s2 ) - { - return s1 != null ? s1.equals( s2 ) : s2 == null; - } - - @Override - public int hashCode() - { - int hash = 17; - hash = hash * 31 + key.hashCode(); - hash = hash * 31 + secretHash; - return hash; - } - - @Override - public String toString() - { - return key + "=" + ( ( value != null ) ? "***" : "null" ); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/repository/SimpleArtifactDescriptorPolicy.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/repository/SimpleArtifactDescriptorPolicy.java b/aether-util/src/main/java/org/eclipse/aether/util/repository/SimpleArtifactDescriptorPolicy.java deleted file mode 100644 index ccf1ba8..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/repository/SimpleArtifactDescriptorPolicy.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.eclipse.aether.util.repository; - -/* - * 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. - */ - -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.resolution.ArtifactDescriptorPolicy; -import org.eclipse.aether.resolution.ArtifactDescriptorPolicyRequest; - -/** - * An artifact descriptor error policy that allows to control error handling at a global level. - */ -public final class SimpleArtifactDescriptorPolicy - implements ArtifactDescriptorPolicy -{ - - private final int policy; - - /** - * Creates a new error policy with the specified behavior. - * - * @param ignoreMissing {@code true} to ignore missing descriptors, {@code false} to fail resolution. - * @param ignoreInvalid {@code true} to ignore invalid descriptors, {@code false} to fail resolution. - */ - public SimpleArtifactDescriptorPolicy( boolean ignoreMissing, boolean ignoreInvalid ) - { - this( ( ignoreMissing ? IGNORE_MISSING : 0 ) | ( ignoreInvalid ? IGNORE_INVALID : 0 ) ); - } - - /** - * Creates a new error policy with the specified bit mask. - * - * @param policy The bit mask describing the policy. - */ - public SimpleArtifactDescriptorPolicy( int policy ) - { - this.policy = policy; - } - - public int getPolicy( RepositorySystemSession session, ArtifactDescriptorPolicyRequest request ) - { - return policy; - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/repository/SimpleResolutionErrorPolicy.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/repository/SimpleResolutionErrorPolicy.java b/aether-util/src/main/java/org/eclipse/aether/util/repository/SimpleResolutionErrorPolicy.java deleted file mode 100644 index 4fa9059..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/repository/SimpleResolutionErrorPolicy.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.eclipse.aether.util.repository; - -/* - * 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. - */ - -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.metadata.Metadata; -import org.eclipse.aether.resolution.ResolutionErrorPolicy; -import org.eclipse.aether.resolution.ResolutionErrorPolicyRequest; - -/** - * A resolution error policy that allows to control caching for artifacts and metadata at a global level. - */ -public final class SimpleResolutionErrorPolicy - implements ResolutionErrorPolicy -{ - - private final int artifactPolicy; - - private final int metadataPolicy; - - /** - * Creates a new error policy with the specified behavior for both artifacts and metadata. - * - * @param cacheNotFound {@code true} to enable caching of missing items, {@code false} to disable it. - * @param cacheTransferErrors {@code true} to enable chaching of transfer errors, {@code false} to disable it. - */ - public SimpleResolutionErrorPolicy( boolean cacheNotFound, boolean cacheTransferErrors ) - { - this( ( cacheNotFound ? CACHE_NOT_FOUND : 0 ) | ( cacheTransferErrors ? CACHE_TRANSFER_ERROR : 0 ) ); - } - - /** - * Creates a new error policy with the specified bit mask for both artifacts and metadata. - * - * @param policy The bit mask describing the policy for artifacts and metadata. - */ - public SimpleResolutionErrorPolicy( int policy ) - { - this( policy, policy ); - } - - /** - * Creates a new error policy with the specified bit masks for artifacts and metadata. - * - * @param artifactPolicy The bit mask describing the policy for artifacts. - * @param metadataPolicy The bit mask describing the policy for metadata. - */ - public SimpleResolutionErrorPolicy( int artifactPolicy, int metadataPolicy ) - { - this.artifactPolicy = artifactPolicy; - this.metadataPolicy = metadataPolicy; - } - - public int getArtifactPolicy( RepositorySystemSession session, ResolutionErrorPolicyRequest<Artifact> request ) - { - return artifactPolicy; - } - - public int getMetadataPolicy( RepositorySystemSession session, ResolutionErrorPolicyRequest<Metadata> request ) - { - return metadataPolicy; - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/repository/StringAuthentication.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/repository/StringAuthentication.java b/aether-util/src/main/java/org/eclipse/aether/util/repository/StringAuthentication.java deleted file mode 100644 index 8438082..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/repository/StringAuthentication.java +++ /dev/null @@ -1,94 +0,0 @@ -package org.eclipse.aether.util.repository; - -/* - * 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. - */ - -import java.util.Map; - -import org.eclipse.aether.repository.Authentication; -import org.eclipse.aether.repository.AuthenticationContext; -import org.eclipse.aether.repository.AuthenticationDigest; - -/** - * Authentication block that manages a single authentication key and its string value. - */ -final class StringAuthentication - implements Authentication -{ - - private final String key; - - private final String value; - - public StringAuthentication( String key, String value ) - { - if ( key == null ) - { - throw new IllegalArgumentException( "authentication key missing" ); - } - this.key = key; - this.value = value; - } - - public void fill( AuthenticationContext context, String key, Map<String, String> data ) - { - context.put( this.key, value ); - } - - public void digest( AuthenticationDigest digest ) - { - digest.update( key, value ); - } - - @Override - public boolean equals( Object obj ) - { - if ( this == obj ) - { - return true; - } - if ( obj == null || !getClass().equals( obj.getClass() ) ) - { - return false; - } - StringAuthentication that = (StringAuthentication) obj; - return eq( key, that.key ) && eq( value, that.value ); - } - - private static <T> boolean eq( T s1, T s2 ) - { - return s1 != null ? s1.equals( s2 ) : s2 == null; - } - - @Override - public int hashCode() - { - int hash = 17; - hash = hash * 31 + key.hashCode(); - hash = hash * 31 + ( ( value != null ) ? value.hashCode() : 0 ); - return hash; - } - - @Override - public String toString() - { - return key + "=" + value; - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/repository/package-info.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/repository/package-info.java b/aether-util/src/main/java/org/eclipse/aether/util/repository/package-info.java deleted file mode 100644 index 1c0a194..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/repository/package-info.java +++ /dev/null @@ -1,24 +0,0 @@ -// CHECKSTYLE_OFF: RegexpHeader -/* - * 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. - */ -/** - * Ready-to-use selectors for authentication, proxies and mirrors and a few other repository related utilities. - */ -package org.eclipse.aether.util.repository; - http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/version/GenericVersion.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/version/GenericVersion.java b/aether-util/src/main/java/org/eclipse/aether/util/version/GenericVersion.java deleted file mode 100644 index 3596a29..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/version/GenericVersion.java +++ /dev/null @@ -1,464 +0,0 @@ -package org.eclipse.aether.util.version; - -/* - * 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. - */ - -import java.math.BigInteger; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.TreeMap; - -import org.eclipse.aether.version.Version; - -/** - * A generic version, that is a version that accepts any input string and tries to apply common sense sorting. See - * {@link GenericVersionScheme} for details. - */ -final class GenericVersion - implements Version -{ - - private final String version; - - private final Item[] items; - - private final int hash; - - /** - * Creates a generic version from the specified string. - * - * @param version The version string, must not be {@code null}. - */ - public GenericVersion( String version ) - { - this.version = version; - items = parse( version ); - hash = Arrays.hashCode( items ); - } - - private static Item[] parse( String version ) - { - List<Item> items = new ArrayList<Item>(); - - for ( Tokenizer tokenizer = new Tokenizer( version ); tokenizer.next(); ) - { - Item item = tokenizer.toItem(); - items.add( item ); - } - - trimPadding( items ); - - return items.toArray( new Item[items.size()] ); - } - - private static void trimPadding( List<Item> items ) - { - Boolean number = null; - int end = items.size() - 1; - for ( int i = end; i > 0; i-- ) - { - Item item = items.get( i ); - if ( !Boolean.valueOf( item.isNumber() ).equals( number ) ) - { - end = i; - number = item.isNumber(); - } - if ( end == i && ( i == items.size() - 1 || items.get( i - 1 ).isNumber() == item.isNumber() ) - && item.compareTo( null ) == 0 ) - { - items.remove( i ); - end--; - } - } - } - - public int compareTo( Version obj ) - { - final Item[] these = items; - final Item[] those = ( (GenericVersion) obj ).items; - - boolean number = true; - - for ( int index = 0;; index++ ) - { - if ( index >= these.length && index >= those.length ) - { - return 0; - } - else if ( index >= these.length ) - { - return -comparePadding( those, index, null ); - } - else if ( index >= those.length ) - { - return comparePadding( these, index, null ); - } - - Item thisItem = these[index]; - Item thatItem = those[index]; - - if ( thisItem.isNumber() != thatItem.isNumber() ) - { - if ( number == thisItem.isNumber() ) - { - return comparePadding( these, index, number ); - } - else - { - return -comparePadding( those, index, number ); - } - } - else - { - int rel = thisItem.compareTo( thatItem ); - if ( rel != 0 ) - { - return rel; - } - number = thisItem.isNumber(); - } - } - } - - private static int comparePadding( Item[] items, int index, Boolean number ) - { - int rel = 0; - for ( int i = index; i < items.length; i++ ) - { - Item item = items[i]; - if ( number != null && number != item.isNumber() ) - { - break; - } - rel = item.compareTo( null ); - if ( rel != 0 ) - { - break; - } - } - return rel; - } - - @Override - public boolean equals( Object obj ) - { - return ( obj instanceof GenericVersion ) && compareTo( (GenericVersion) obj ) == 0; - } - - @Override - public int hashCode() - { - return hash; - } - - @Override - public String toString() - { - return version; - } - - static final class Tokenizer - { - - private static final Integer QUALIFIER_ALPHA = -5; - - private static final Integer QUALIFIER_BETA = -4; - - private static final Integer QUALIFIER_MILESTONE = -3; - - private static final Map<String, Integer> QUALIFIERS; - - static - { - QUALIFIERS = new TreeMap<String, Integer>( String.CASE_INSENSITIVE_ORDER ); - QUALIFIERS.put( "alpha", QUALIFIER_ALPHA ); - QUALIFIERS.put( "beta", QUALIFIER_BETA ); - QUALIFIERS.put( "milestone", QUALIFIER_MILESTONE ); - QUALIFIERS.put( "cr", -2 ); - QUALIFIERS.put( "rc", -2 ); - QUALIFIERS.put( "snapshot", -1 ); - QUALIFIERS.put( "ga", 0 ); - QUALIFIERS.put( "final", 0 ); - QUALIFIERS.put( "", 0 ); - QUALIFIERS.put( "sp", 1 ); - } - - private final String version; - - private int index; - - private String token; - - private boolean number; - - private boolean terminatedByNumber; - - public Tokenizer( String version ) - { - this.version = ( version.length() > 0 ) ? version : "0"; - } - - public boolean next() - { - final int n = version.length(); - if ( index >= n ) - { - return false; - } - - int state = -2; - - int start = index; - int end = n; - terminatedByNumber = false; - - for ( ; index < n; index++ ) - { - char c = version.charAt( index ); - - if ( c == '.' || c == '-' || c == '_' ) - { - end = index; - index++; - break; - } - else - { - int digit = Character.digit( c, 10 ); - if ( digit >= 0 ) - { - if ( state == -1 ) - { - end = index; - terminatedByNumber = true; - break; - } - if ( state == 0 ) - { - // normalize numbers and strip leading zeros (prereq for Integer/BigInteger handling) - start++; - } - state = ( state > 0 || digit > 0 ) ? 1 : 0; - } - else - { - if ( state >= 0 ) - { - end = index; - break; - } - state = -1; - } - } - - } - - if ( end - start > 0 ) - { - token = version.substring( start, end ); - number = state >= 0; - } - else - { - token = "0"; - number = true; - } - - return true; - } - - @Override - public String toString() - { - return String.valueOf( token ); - } - - public Item toItem() - { - if ( number ) - { - try - { - if ( token.length() < 10 ) - { - return new Item( Item.KIND_INT, Integer.parseInt( token ) ); - } - else - { - return new Item( Item.KIND_BIGINT, new BigInteger( token ) ); - } - } - catch ( NumberFormatException e ) - { - throw new IllegalStateException( e ); - } - } - else - { - if ( index >= version.length() ) - { - if ( "min".equalsIgnoreCase( token ) ) - { - return Item.MIN; - } - else if ( "max".equalsIgnoreCase( token ) ) - { - return Item.MAX; - } - } - if ( terminatedByNumber && token.length() == 1 ) - { - switch ( token.charAt( 0 ) ) - { - case 'a': - case 'A': - return new Item( Item.KIND_QUALIFIER, QUALIFIER_ALPHA ); - case 'b': - case 'B': - return new Item( Item.KIND_QUALIFIER, QUALIFIER_BETA ); - case 'm': - case 'M': - return new Item( Item.KIND_QUALIFIER, QUALIFIER_MILESTONE ); - default: - } - } - Integer qualifier = QUALIFIERS.get( token ); - if ( qualifier != null ) - { - return new Item( Item.KIND_QUALIFIER, qualifier ); - } - else - { - return new Item( Item.KIND_STRING, token.toLowerCase( Locale.ENGLISH ) ); - } - } - } - - } - - static final class Item - { - - static final int KIND_MAX = 8; - - static final int KIND_BIGINT = 5; - - static final int KIND_INT = 4; - - static final int KIND_STRING = 3; - - static final int KIND_QUALIFIER = 2; - - static final int KIND_MIN = 0; - - static final Item MAX = new Item( KIND_MAX, "max" ); - - static final Item MIN = new Item( KIND_MIN, "min" ); - - private final int kind; - - private final Object value; - - public Item( int kind, Object value ) - { - this.kind = kind; - this.value = value; - } - - public boolean isNumber() - { - return ( kind & KIND_QUALIFIER ) == 0; // i.e. kind != string/qualifier - } - - public int compareTo( Item that ) - { - int rel; - if ( that == null ) - { - // null in this context denotes the pad item (0 or "ga") - switch ( kind ) - { - case KIND_MIN: - rel = -1; - break; - case KIND_MAX: - case KIND_BIGINT: - case KIND_STRING: - rel = 1; - break; - case KIND_INT: - case KIND_QUALIFIER: - rel = (Integer) value; - break; - default: - throw new IllegalStateException( "unknown version item kind " + kind ); - } - } - else - { - rel = kind - that.kind; - if ( rel == 0 ) - { - switch ( kind ) - { - case KIND_MAX: - case KIND_MIN: - break; - case KIND_BIGINT: - rel = ( (BigInteger) value ).compareTo( (BigInteger) that.value ); - break; - case KIND_INT: - case KIND_QUALIFIER: - rel = ( (Integer) value ).compareTo( (Integer) that.value ); - break; - case KIND_STRING: - rel = ( (String) value ).compareToIgnoreCase( (String) that.value ); - break; - default: - throw new IllegalStateException( "unknown version item kind " + kind ); - } - } - } - return rel; - } - - @Override - public boolean equals( Object obj ) - { - return ( obj instanceof Item ) && compareTo( (Item) obj ) == 0; - } - - @Override - public int hashCode() - { - return value.hashCode() + kind * 31; - } - - @Override - public String toString() - { - return String.valueOf( value ); - } - - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-util/src/main/java/org/eclipse/aether/util/version/GenericVersionConstraint.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/version/GenericVersionConstraint.java b/aether-util/src/main/java/org/eclipse/aether/util/version/GenericVersionConstraint.java deleted file mode 100644 index bfcd455..0000000 --- a/aether-util/src/main/java/org/eclipse/aether/util/version/GenericVersionConstraint.java +++ /dev/null @@ -1,131 +0,0 @@ -package org.eclipse.aether.util.version; - -/* - * 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. - */ - -import org.eclipse.aether.version.Version; -import org.eclipse.aether.version.VersionConstraint; -import org.eclipse.aether.version.VersionRange; - -/** - * A constraint on versions for a dependency. - */ -final class GenericVersionConstraint - implements VersionConstraint -{ - - private final VersionRange range; - - private final Version version; - - /** - * Creates a version constraint from the specified version range. - * - * @param range The version range, must not be {@code null}. - */ - public GenericVersionConstraint( VersionRange range ) - { - if ( range == null ) - { - throw new IllegalArgumentException( "version range missing" ); - } - this.range = range; - this.version = null; - } - - /** - * Creates a version constraint from the specified version. - * - * @param version The version, must not be {@code null}. - */ - public GenericVersionConstraint( Version version ) - { - if ( version == null ) - { - throw new IllegalArgumentException( "version missing" ); - } - this.version = version; - this.range = null; - } - - public VersionRange getRange() - { - return range; - } - - public Version getVersion() - { - return version; - } - - public boolean containsVersion( Version version ) - { - if ( range == null ) - { - return version.equals( this.version ); - } - else - { - return range.containsVersion( version ); - } - } - - @Override - public String toString() - { - return String.valueOf( ( range == null ) ? version : range ); - } - - @Override - public boolean equals( Object obj ) - { - if ( this == obj ) - { - return true; - } - if ( obj == null || !getClass().equals( obj.getClass() ) ) - { - return false; - } - - GenericVersionConstraint that = (GenericVersionConstraint) obj; - - return eq( range, that.range ) && eq( version, that.getVersion() ); - } - - private static <T> boolean eq( T s1, T s2 ) - { - return s1 != null ? s1.equals( s2 ) : s2 == null; - } - - @Override - public int hashCode() - { - int hash = 17; - hash = hash * 31 + hash( getRange() ); - hash = hash * 31 + hash( getVersion() ); - return hash; - } - - private static int hash( Object obj ) - { - return obj != null ? obj.hashCode() : 0; - } - -}