Modified: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/repository/RepositoryManagerException.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/repository/RepositoryManagerException.java?rev=1685372&r1=1685371&r2=1685372&view=diff ============================================================================== --- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/repository/RepositoryManagerException.java (original) +++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/repository/RepositoryManagerException.java Sun Jun 14 09:40:45 2015 @@ -1,33 +1,33 @@ -package org.apache.maven.shared.artifact.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. - */ - -/** - * - */ -public class RepositoryManagerException extends Exception -{ - - public RepositoryManagerException( String message, Throwable cause ) - { - super( message, cause ); - } - -} +package org.apache.maven.shared.artifact.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. + */ + +/** + * + */ +public class RepositoryManagerException extends Exception +{ + + public RepositoryManagerException( String message, Throwable cause ) + { + super( message, cause ); + } + +}
Modified: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/repository/internal/DefaultRepositoryManager.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/repository/internal/DefaultRepositoryManager.java?rev=1685372&r1=1685371&r2=1685372&view=diff ============================================================================== --- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/repository/internal/DefaultRepositoryManager.java (original) +++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/repository/internal/DefaultRepositoryManager.java Sun Jun 14 09:40:45 2015 @@ -1,143 +1,143 @@ -package org.apache.maven.shared.artifact.repository.internal; - -/* - * 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 org.apache.maven.artifact.Artifact; -import org.apache.maven.project.ProjectBuildingRequest; -import org.apache.maven.shared.artifact.repository.RepositoryManager; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import org.codehaus.plexus.context.Context; -import org.codehaus.plexus.context.ContextException; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; - -/** - * - */ -@Component( role = RepositoryManager.class ) -public class DefaultRepositoryManager - implements RepositoryManager, Contextualizable -{ - private PlexusContainer container; - - /** - * {@inheritDoc} - */ - public String getPathForLocalArtifact( ProjectBuildingRequest buildingRequest, Artifact artifact ) - { - try - { - String hint = isMaven31() ? "maven31" : "maven3"; - - RepositoryManager effectiveRepositoryManager = container.lookup( RepositoryManager.class, hint ); - - return effectiveRepositoryManager.getPathForLocalArtifact( buildingRequest, artifact ); - } - catch ( ComponentLookupException e ) - { - throw new IllegalStateException( e.getMessage(), e ); - } - - } - - /** - * {@inheritDoc} - */ - public ProjectBuildingRequest setLocalRepositoryBasedir( ProjectBuildingRequest request, File basedir ) - { - try - { - String hint = isMaven31() ? "maven31" : isMaven302() ? "maven302" : "maven3"; - - RepositoryManager effectiveRepositoryManager = container.lookup( RepositoryManager.class, hint ); - - return effectiveRepositoryManager.setLocalRepositoryBasedir( request, basedir ); - } - catch ( ComponentLookupException e ) - { - throw new IllegalStateException( e.getMessage(), e ); - } - } - - /** - * {@inheritDoc} - */ - public File getLocalRepositoryBasedir( ProjectBuildingRequest request ) - { - try - { - String hint = isMaven31() ? "maven31" : isMaven302() ? "maven302" : "maven3"; - - RepositoryManager effectiveRepositoryManager = container.lookup( RepositoryManager.class, hint ); - - return effectiveRepositoryManager.getLocalRepositoryBasedir( request ); - } - catch ( ComponentLookupException e ) - { - throw new IllegalStateException( e.getMessage(), e ); - } - } - - /** - * @return true if the current Maven version is Maven 3.1. - */ - protected static boolean isMaven31() - { - return canFindCoreClass( "org.eclipse.aether.artifact.Artifact" ); // Maven 3.1 specific - } - - /** - * @return true if the current Maven version is Maven 3.0.2 - */ - protected static boolean isMaven302() - { - return canFindCoreClass( "org.sonatype.aether.spi.localrepo.LocalRepositoryManagerFactory" ); - } - - private static boolean canFindCoreClass( String className ) - { - try - { - Thread.currentThread().getContextClassLoader().loadClass( className ); - - return true; - } - catch ( ClassNotFoundException e ) - { - return false; - } - } - - /** - * Injects the Plexus content. - * - * @param context Plexus context to inject. - * @throws ContextException if the PlexusContainer could not be located. - */ - public void contextualize( Context context ) - throws ContextException - { - container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); - } -} +package org.apache.maven.shared.artifact.repository.internal; + +/* + * 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 org.apache.maven.artifact.Artifact; +import org.apache.maven.project.ProjectBuildingRequest; +import org.apache.maven.shared.artifact.repository.RepositoryManager; +import org.codehaus.plexus.PlexusConstants; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.context.Context; +import org.codehaus.plexus.context.ContextException; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; + +/** + * + */ +@Component( role = RepositoryManager.class ) +public class DefaultRepositoryManager + implements RepositoryManager, Contextualizable +{ + private PlexusContainer container; + + /** + * {@inheritDoc} + */ + public String getPathForLocalArtifact( ProjectBuildingRequest buildingRequest, Artifact artifact ) + { + try + { + String hint = isMaven31() ? "maven31" : "maven3"; + + RepositoryManager effectiveRepositoryManager = container.lookup( RepositoryManager.class, hint ); + + return effectiveRepositoryManager.getPathForLocalArtifact( buildingRequest, artifact ); + } + catch ( ComponentLookupException e ) + { + throw new IllegalStateException( e.getMessage(), e ); + } + + } + + /** + * {@inheritDoc} + */ + public ProjectBuildingRequest setLocalRepositoryBasedir( ProjectBuildingRequest request, File basedir ) + { + try + { + String hint = isMaven31() ? "maven31" : isMaven302() ? "maven302" : "maven3"; + + RepositoryManager effectiveRepositoryManager = container.lookup( RepositoryManager.class, hint ); + + return effectiveRepositoryManager.setLocalRepositoryBasedir( request, basedir ); + } + catch ( ComponentLookupException e ) + { + throw new IllegalStateException( e.getMessage(), e ); + } + } + + /** + * {@inheritDoc} + */ + public File getLocalRepositoryBasedir( ProjectBuildingRequest request ) + { + try + { + String hint = isMaven31() ? "maven31" : isMaven302() ? "maven302" : "maven3"; + + RepositoryManager effectiveRepositoryManager = container.lookup( RepositoryManager.class, hint ); + + return effectiveRepositoryManager.getLocalRepositoryBasedir( request ); + } + catch ( ComponentLookupException e ) + { + throw new IllegalStateException( e.getMessage(), e ); + } + } + + /** + * @return true if the current Maven version is Maven 3.1. + */ + protected static boolean isMaven31() + { + return canFindCoreClass( "org.eclipse.aether.artifact.Artifact" ); // Maven 3.1 specific + } + + /** + * @return true if the current Maven version is Maven 3.0.2 + */ + protected static boolean isMaven302() + { + return canFindCoreClass( "org.sonatype.aether.spi.localrepo.LocalRepositoryManagerFactory" ); + } + + private static boolean canFindCoreClass( String className ) + { + try + { + Thread.currentThread().getContextClassLoader().loadClass( className ); + + return true; + } + catch ( ClassNotFoundException e ) + { + return false; + } + } + + /** + * Injects the Plexus content. + * + * @param context Plexus context to inject. + * @throws ContextException if the PlexusContainer could not be located. + */ + public void contextualize( Context context ) + throws ContextException + { + container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); + } +} Modified: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/repository/internal/Maven302RepositoryManager.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/repository/internal/Maven302RepositoryManager.java?rev=1685372&r1=1685371&r2=1685372&view=diff ============================================================================== --- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/repository/internal/Maven302RepositoryManager.java (original) +++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/repository/internal/Maven302RepositoryManager.java Sun Jun 14 09:40:45 2015 @@ -1,52 +1,52 @@ -package org.apache.maven.shared.artifact.repository.internal; - -/* - * 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.apache.maven.shared.artifact.repository.RepositoryManager; -import org.codehaus.plexus.component.annotations.Component; -import org.sonatype.aether.repository.LocalRepository; - -/** - * - */ -@Component( role = RepositoryManager.class, hint = "maven302" ) -public class Maven302RepositoryManager - extends Maven30RepositoryManager -{ - - /** - * Aether-1.9+ (i.e. M3.0.2+) expects "default", not "enhanced" as repositoryType - */ - @Override - protected String resolveRepositoryType( LocalRepository localRepository ) - { - String repositoryType; - if ( "enhanced".equals( localRepository.getContentType() ) ) - { - repositoryType = "default"; - } - else - { - // this should be "simple" - repositoryType = localRepository.getContentType(); - } - return repositoryType; - } -} +package org.apache.maven.shared.artifact.repository.internal; + +/* + * 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.apache.maven.shared.artifact.repository.RepositoryManager; +import org.codehaus.plexus.component.annotations.Component; +import org.sonatype.aether.repository.LocalRepository; + +/** + * + */ +@Component( role = RepositoryManager.class, hint = "maven302" ) +public class Maven302RepositoryManager + extends Maven30RepositoryManager +{ + + /** + * Aether-1.9+ (i.e. M3.0.2+) expects "default", not "enhanced" as repositoryType + */ + @Override + protected String resolveRepositoryType( LocalRepository localRepository ) + { + String repositoryType; + if ( "enhanced".equals( localRepository.getContentType() ) ) + { + repositoryType = "default"; + } + else + { + // this should be "simple" + repositoryType = localRepository.getContentType(); + } + return repositoryType; + } +} Modified: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/repository/internal/Maven30RepositoryManager.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/repository/internal/Maven30RepositoryManager.java?rev=1685372&r1=1685371&r2=1685372&view=diff ============================================================================== --- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/repository/internal/Maven30RepositoryManager.java (original) +++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/repository/internal/Maven30RepositoryManager.java Sun Jun 14 09:40:45 2015 @@ -1,141 +1,141 @@ -package org.apache.maven.shared.artifact.repository.internal; - -/* - * 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 org.apache.maven.RepositoryUtils; -import org.apache.maven.project.DefaultProjectBuildingRequest; -import org.apache.maven.project.ProjectBuildingRequest; -import org.apache.maven.shared.artifact.repository.RepositoryManager; -import org.apache.maven.shared.artifact.repository.RepositoryManagerException; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; -import org.sonatype.aether.RepositorySystem; -import org.sonatype.aether.RepositorySystemSession; -import org.sonatype.aether.artifact.Artifact; -import org.sonatype.aether.repository.LocalRepository; -import org.sonatype.aether.repository.LocalRepositoryManager; -import org.sonatype.aether.util.DefaultRepositoryCache; -import org.sonatype.aether.util.DefaultRepositorySystemSession; - -/** - * - */ -@Component( role = RepositoryManager.class, hint = "maven3" ) -public class Maven30RepositoryManager - implements RepositoryManager -{ - - @Requirement - private RepositorySystem repositorySystem; - - /** - * {@inheritDoc} - */ - public String getPathForLocalArtifact( ProjectBuildingRequest buildingRequest, - org.apache.maven.artifact.Artifact mavenArtifact ) - { - Artifact aetherArtifact; - RepositorySystemSession session; - - // LRM.getPathForLocalArtifact() won't throw an Exception, so translate reflection error to RuntimeException - try - { - aetherArtifact = - (Artifact) Invoker.invoke( RepositoryUtils.class, "toArtifact", - org.apache.maven.artifact.Artifact.class, mavenArtifact ); - - session = (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" ); - } - catch ( RepositoryManagerException e ) - { - throw new RuntimeException( e.getMessage(), e ); - } - - return session.getLocalRepositoryManager().getPathForLocalArtifact( aetherArtifact ); - } - - /** - * {@inheritDoc} - */ - public ProjectBuildingRequest setLocalRepositoryBasedir( ProjectBuildingRequest buildingRequest, File basedir ) - { - ProjectBuildingRequest newRequest = new DefaultProjectBuildingRequest( buildingRequest ); - - RepositorySystemSession session; - try - { - session = (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" ); - } - catch ( RepositoryManagerException e ) - { - throw new RuntimeException( e.getMessage(), e ); - } - - // "clone" session and replace localRepository - DefaultRepositorySystemSession newSession = new DefaultRepositorySystemSession( session ); - - // Clear cache, since we're using a new local repository - newSession.setCache( new DefaultRepositoryCache() ); - - // keep same repositoryType - String repositoryType = resolveRepositoryType( session.getLocalRepository() ); - - LocalRepositoryManager localRepositoryManager = - repositorySystem.newLocalRepositoryManager( new LocalRepository( basedir, repositoryType ) ); - - newSession.setLocalRepositoryManager( localRepositoryManager ); - - try - { - Invoker.invoke( newRequest, "setRepositorySession", RepositorySystemSession.class, newSession ); - } - catch ( RepositoryManagerException e ) - { - throw new RuntimeException( e.getMessage(), e ); - } - - return newRequest; - } - - /** - * {@inheritDoc} - */ - public File getLocalRepositoryBasedir( ProjectBuildingRequest buildingRequest ) - { - RepositorySystemSession session; - try - { - session = (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" ); - } - catch ( RepositoryManagerException e ) - { - throw new RuntimeException( e.getMessage(), e ); - } - - return session.getLocalRepository().getBasedir(); - } - - protected String resolveRepositoryType( LocalRepository localRepository ) - { - return localRepository.getContentType(); - } -} +package org.apache.maven.shared.artifact.repository.internal; + +/* + * 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 org.apache.maven.RepositoryUtils; +import org.apache.maven.project.DefaultProjectBuildingRequest; +import org.apache.maven.project.ProjectBuildingRequest; +import org.apache.maven.shared.artifact.repository.RepositoryManager; +import org.apache.maven.shared.artifact.repository.RepositoryManagerException; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; +import org.sonatype.aether.RepositorySystem; +import org.sonatype.aether.RepositorySystemSession; +import org.sonatype.aether.artifact.Artifact; +import org.sonatype.aether.repository.LocalRepository; +import org.sonatype.aether.repository.LocalRepositoryManager; +import org.sonatype.aether.util.DefaultRepositoryCache; +import org.sonatype.aether.util.DefaultRepositorySystemSession; + +/** + * + */ +@Component( role = RepositoryManager.class, hint = "maven3" ) +public class Maven30RepositoryManager + implements RepositoryManager +{ + + @Requirement + private RepositorySystem repositorySystem; + + /** + * {@inheritDoc} + */ + public String getPathForLocalArtifact( ProjectBuildingRequest buildingRequest, + org.apache.maven.artifact.Artifact mavenArtifact ) + { + Artifact aetherArtifact; + RepositorySystemSession session; + + // LRM.getPathForLocalArtifact() won't throw an Exception, so translate reflection error to RuntimeException + try + { + aetherArtifact = + (Artifact) Invoker.invoke( RepositoryUtils.class, "toArtifact", + org.apache.maven.artifact.Artifact.class, mavenArtifact ); + + session = (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" ); + } + catch ( RepositoryManagerException e ) + { + throw new RuntimeException( e.getMessage(), e ); + } + + return session.getLocalRepositoryManager().getPathForLocalArtifact( aetherArtifact ); + } + + /** + * {@inheritDoc} + */ + public ProjectBuildingRequest setLocalRepositoryBasedir( ProjectBuildingRequest buildingRequest, File basedir ) + { + ProjectBuildingRequest newRequest = new DefaultProjectBuildingRequest( buildingRequest ); + + RepositorySystemSession session; + try + { + session = (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" ); + } + catch ( RepositoryManagerException e ) + { + throw new RuntimeException( e.getMessage(), e ); + } + + // "clone" session and replace localRepository + DefaultRepositorySystemSession newSession = new DefaultRepositorySystemSession( session ); + + // Clear cache, since we're using a new local repository + newSession.setCache( new DefaultRepositoryCache() ); + + // keep same repositoryType + String repositoryType = resolveRepositoryType( session.getLocalRepository() ); + + LocalRepositoryManager localRepositoryManager = + repositorySystem.newLocalRepositoryManager( new LocalRepository( basedir, repositoryType ) ); + + newSession.setLocalRepositoryManager( localRepositoryManager ); + + try + { + Invoker.invoke( newRequest, "setRepositorySession", RepositorySystemSession.class, newSession ); + } + catch ( RepositoryManagerException e ) + { + throw new RuntimeException( e.getMessage(), e ); + } + + return newRequest; + } + + /** + * {@inheritDoc} + */ + public File getLocalRepositoryBasedir( ProjectBuildingRequest buildingRequest ) + { + RepositorySystemSession session; + try + { + session = (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" ); + } + catch ( RepositoryManagerException e ) + { + throw new RuntimeException( e.getMessage(), e ); + } + + return session.getLocalRepository().getBasedir(); + } + + protected String resolveRepositoryType( LocalRepository localRepository ) + { + return localRepository.getContentType(); + } +} Modified: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/repository/internal/Maven31RepositoryManager.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/repository/internal/Maven31RepositoryManager.java?rev=1685372&r1=1685371&r2=1685372&view=diff ============================================================================== --- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/repository/internal/Maven31RepositoryManager.java (original) +++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/repository/internal/Maven31RepositoryManager.java Sun Jun 14 09:40:45 2015 @@ -1,142 +1,142 @@ -package org.apache.maven.shared.artifact.repository.internal; - -/* - * 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 org.apache.maven.RepositoryUtils; -import org.apache.maven.project.DefaultProjectBuildingRequest; -import org.apache.maven.project.ProjectBuildingRequest; -import org.apache.maven.shared.artifact.repository.RepositoryManager; -import org.apache.maven.shared.artifact.repository.RepositoryManagerException; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; -import org.eclipse.aether.DefaultRepositoryCache; -import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.repository.LocalRepository; -import org.eclipse.aether.repository.LocalRepositoryManager; - -/** - * - */ -@Component( role = RepositoryManager.class, hint = "maven31" ) -public class Maven31RepositoryManager - implements RepositoryManager -{ - - @Requirement - private RepositorySystem repositorySystem; - - public String getPathForLocalArtifact( ProjectBuildingRequest buildingRequest, - org.apache.maven.artifact.Artifact mavenArtifact ) - { - Artifact aetherArtifact; - RepositorySystemSession session; - - // LRM.getPathForLocalArtifact() won't throw an Exception, so translate reflection error to RuntimeException - try - { - aetherArtifact = - (Artifact) Invoker.invoke( RepositoryUtils.class, "toArtifact", - org.apache.maven.artifact.Artifact.class, mavenArtifact ); - - session = (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" ); - } - catch ( RepositoryManagerException e ) - { - throw new RuntimeException( e.getMessage(), e ); - } - - return session.getLocalRepositoryManager().getPathForLocalArtifact( aetherArtifact ); - } - - public ProjectBuildingRequest setLocalRepositoryBasedir( ProjectBuildingRequest buildingRequest, File basedir ) - { - ProjectBuildingRequest newRequest = new DefaultProjectBuildingRequest( buildingRequest ); - - RepositorySystemSession session; - try - { - session = (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" ); - } - catch ( RepositoryManagerException e ) - { - throw new RuntimeException( e.getMessage(), e ); - } - - // "clone" session and replace localRepository - DefaultRepositorySystemSession newSession = new DefaultRepositorySystemSession( session ); - - // Clear cache, since we're using a new local repository - newSession.setCache( new DefaultRepositoryCache() ); - - // keep same repositoryType - String repositoryType = resolveRepositoryType( session.getLocalRepository() ); - - LocalRepositoryManager localRepositoryManager = - repositorySystem.newLocalRepositoryManager( newSession, new LocalRepository( basedir, repositoryType ) ); - - newSession.setLocalRepositoryManager( localRepositoryManager ); - - try - { - Invoker.invoke( newRequest, "setRepositorySession", RepositorySystemSession.class, newSession ); - } - catch ( RepositoryManagerException e ) - { - throw new RuntimeException( e.getMessage(), e ); - } - - return newRequest; - } - - public File getLocalRepositoryBasedir( ProjectBuildingRequest buildingRequest ) - { - RepositorySystemSession session; - try - { - session = (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" ); - } - catch ( RepositoryManagerException e ) - { - throw new RuntimeException( e.getMessage(), e ); - } - - return session.getLocalRepository().getBasedir(); - } - - protected String resolveRepositoryType( LocalRepository localRepository ) - { - String repositoryType; - if ( "enhanced".equals( localRepository.getContentType() ) ) - { - repositoryType = "default"; - } - else - { - // this should be "simple" - repositoryType = localRepository.getContentType(); - } - return repositoryType; - } -} +package org.apache.maven.shared.artifact.repository.internal; + +/* + * 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 org.apache.maven.RepositoryUtils; +import org.apache.maven.project.DefaultProjectBuildingRequest; +import org.apache.maven.project.ProjectBuildingRequest; +import org.apache.maven.shared.artifact.repository.RepositoryManager; +import org.apache.maven.shared.artifact.repository.RepositoryManagerException; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; +import org.eclipse.aether.DefaultRepositoryCache; +import org.eclipse.aether.DefaultRepositorySystemSession; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.repository.LocalRepository; +import org.eclipse.aether.repository.LocalRepositoryManager; + +/** + * + */ +@Component( role = RepositoryManager.class, hint = "maven31" ) +public class Maven31RepositoryManager + implements RepositoryManager +{ + + @Requirement + private RepositorySystem repositorySystem; + + public String getPathForLocalArtifact( ProjectBuildingRequest buildingRequest, + org.apache.maven.artifact.Artifact mavenArtifact ) + { + Artifact aetherArtifact; + RepositorySystemSession session; + + // LRM.getPathForLocalArtifact() won't throw an Exception, so translate reflection error to RuntimeException + try + { + aetherArtifact = + (Artifact) Invoker.invoke( RepositoryUtils.class, "toArtifact", + org.apache.maven.artifact.Artifact.class, mavenArtifact ); + + session = (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" ); + } + catch ( RepositoryManagerException e ) + { + throw new RuntimeException( e.getMessage(), e ); + } + + return session.getLocalRepositoryManager().getPathForLocalArtifact( aetherArtifact ); + } + + public ProjectBuildingRequest setLocalRepositoryBasedir( ProjectBuildingRequest buildingRequest, File basedir ) + { + ProjectBuildingRequest newRequest = new DefaultProjectBuildingRequest( buildingRequest ); + + RepositorySystemSession session; + try + { + session = (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" ); + } + catch ( RepositoryManagerException e ) + { + throw new RuntimeException( e.getMessage(), e ); + } + + // "clone" session and replace localRepository + DefaultRepositorySystemSession newSession = new DefaultRepositorySystemSession( session ); + + // Clear cache, since we're using a new local repository + newSession.setCache( new DefaultRepositoryCache() ); + + // keep same repositoryType + String repositoryType = resolveRepositoryType( session.getLocalRepository() ); + + LocalRepositoryManager localRepositoryManager = + repositorySystem.newLocalRepositoryManager( newSession, new LocalRepository( basedir, repositoryType ) ); + + newSession.setLocalRepositoryManager( localRepositoryManager ); + + try + { + Invoker.invoke( newRequest, "setRepositorySession", RepositorySystemSession.class, newSession ); + } + catch ( RepositoryManagerException e ) + { + throw new RuntimeException( e.getMessage(), e ); + } + + return newRequest; + } + + public File getLocalRepositoryBasedir( ProjectBuildingRequest buildingRequest ) + { + RepositorySystemSession session; + try + { + session = (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" ); + } + catch ( RepositoryManagerException e ) + { + throw new RuntimeException( e.getMessage(), e ); + } + + return session.getLocalRepository().getBasedir(); + } + + protected String resolveRepositoryType( LocalRepository localRepository ) + { + String repositoryType; + if ( "enhanced".equals( localRepository.getContentType() ) ) + { + repositoryType = "default"; + } + else + { + // this should be "simple" + repositoryType = localRepository.getContentType(); + } + return repositoryType; + } +} Modified: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/ArtifactResolver.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/ArtifactResolver.java?rev=1685372&r1=1685371&r2=1685372&view=diff ============================================================================== --- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/ArtifactResolver.java (original) +++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/ArtifactResolver.java Sun Jun 14 09:40:45 2015 @@ -1,47 +1,47 @@ -package org.apache.maven.shared.artifact.resolve; - -/* - * 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.List; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.project.ProjectBuildingRequest; -import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter; - -/** - * - */ -public interface ArtifactResolver -{ - - Artifact resolveArtifact( ProjectBuildingRequest buildingRequest, Artifact mavenArtifact, - List<ArtifactRepository> remoteRepositories ) - throws ArtifactResolverException; - - void resolveTransitively( ProjectBuildingRequest buildingRequest, Artifact mavenArtifact, - List<ArtifactRepository> remoteRepositories ) - throws ArtifactResolverException; - - void resolveTransitively( ProjectBuildingRequest buildingRequest, Artifact mavenArtifact, - List<ArtifactRepository> remoteRepositories, TransformableFilter filter ) - throws ArtifactResolverException; - -} +package org.apache.maven.shared.artifact.resolve; + +/* + * 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.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.project.ProjectBuildingRequest; +import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter; + +/** + * + */ +public interface ArtifactResolver +{ + + Artifact resolveArtifact( ProjectBuildingRequest buildingRequest, Artifact mavenArtifact, + List<ArtifactRepository> remoteRepositories ) + throws ArtifactResolverException; + + void resolveTransitively( ProjectBuildingRequest buildingRequest, Artifact mavenArtifact, + List<ArtifactRepository> remoteRepositories ) + throws ArtifactResolverException; + + void resolveTransitively( ProjectBuildingRequest buildingRequest, Artifact mavenArtifact, + List<ArtifactRepository> remoteRepositories, TransformableFilter filter ) + throws ArtifactResolverException; + +} Modified: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/ArtifactResolverException.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/ArtifactResolverException.java?rev=1685372&r1=1685371&r2=1685372&view=diff ============================================================================== --- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/ArtifactResolverException.java (original) +++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/ArtifactResolverException.java Sun Jun 14 09:40:45 2015 @@ -1,33 +1,33 @@ -package org.apache.maven.shared.artifact.resolve; - -/* - * 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. - */ - -/** - * - */ -public class ArtifactResolverException extends Exception -{ - - public ArtifactResolverException( String message, Exception e ) - { - super( message, e ); - } - -} +package org.apache.maven.shared.artifact.resolve; + +/* + * 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. + */ + +/** + * + */ +public class ArtifactResolverException extends Exception +{ + + public ArtifactResolverException( String message, Exception e ) + { + super( message, e ); + } + +} Modified: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/DefaultArtifactResolver.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/DefaultArtifactResolver.java?rev=1685372&r1=1685371&r2=1685372&view=diff ============================================================================== --- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/DefaultArtifactResolver.java (original) +++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/DefaultArtifactResolver.java Sun Jun 14 09:40:45 2015 @@ -1,135 +1,135 @@ -package org.apache.maven.shared.artifact.resolve.internal; - -/* - * 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.List; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.project.ProjectBuildingRequest; -import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter; -import org.apache.maven.shared.artifact.resolve.ArtifactResolver; -import org.apache.maven.shared.artifact.resolve.ArtifactResolverException; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import org.codehaus.plexus.context.Context; -import org.codehaus.plexus.context.ContextException; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; - -/** - * - */ -@Component( role = ArtifactResolver.class, hint = "default" ) -public class DefaultArtifactResolver - implements ArtifactResolver, Contextualizable -{ - private PlexusContainer container; - - public Artifact resolveArtifact( ProjectBuildingRequest buildingRequest, Artifact mavenArtifact, - List<ArtifactRepository> remoteRepositories ) - throws ArtifactResolverException - { - try - { - String hint = isMaven31() ? "maven31" : "maven3"; - - ArtifactResolver effectiveArtifactResolver = container.lookup( ArtifactResolver.class, hint ); - - return effectiveArtifactResolver.resolveArtifact( buildingRequest, mavenArtifact, remoteRepositories ); - } - catch ( ComponentLookupException e ) - { - throw new ArtifactResolverException( e.getMessage(), e ); - } - } - - public void resolveTransitively( ProjectBuildingRequest buildingRequest, Artifact mavenArtifact, - List<ArtifactRepository> remoteRepositories ) - throws ArtifactResolverException - { - try - { - String hint = isMaven31() ? "maven31" : "maven3"; - - ArtifactResolver effectiveArtifactResolver = container.lookup( ArtifactResolver.class, hint ); - - effectiveArtifactResolver.resolveTransitively( buildingRequest, mavenArtifact, remoteRepositories ); - } - catch ( ComponentLookupException e ) - { - throw new ArtifactResolverException( e.getMessage(), e ); - } - } - - public void resolveTransitively( ProjectBuildingRequest buildingRequest, Artifact mavenArtifact, - List<ArtifactRepository> remoteRepositories, TransformableFilter filter ) - throws ArtifactResolverException - { - try - { - String hint = isMaven31() ? "maven31" : "maven3"; - - ArtifactResolver effectiveArtifactResolver = container.lookup( ArtifactResolver.class, hint ); - - effectiveArtifactResolver.resolveTransitively( buildingRequest, mavenArtifact, remoteRepositories, filter ); - } - catch ( ComponentLookupException e ) - { - throw new ArtifactResolverException( e.getMessage(), e ); - } - } - - /** - * @return true if the current Maven version is Maven 3.1. - */ - protected static boolean isMaven31() - { - return canFindCoreClass( "org.eclipse.aether.artifact.Artifact" ); // Maven 3.1 specific - } - - private static boolean canFindCoreClass( String className ) - { - try - { - Thread.currentThread().getContextClassLoader().loadClass( className ); - - return true; - } - catch ( ClassNotFoundException e ) - { - return false; - } - } - - /** - * Injects the Plexus content. - * - * @param context Plexus context to inject. - * @throws ContextException if the PlexusContainer could not be located. - */ - public void contextualize( Context context ) - throws ContextException - { - container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); - } - -} +package org.apache.maven.shared.artifact.resolve.internal; + +/* + * 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.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.project.ProjectBuildingRequest; +import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter; +import org.apache.maven.shared.artifact.resolve.ArtifactResolver; +import org.apache.maven.shared.artifact.resolve.ArtifactResolverException; +import org.codehaus.plexus.PlexusConstants; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.context.Context; +import org.codehaus.plexus.context.ContextException; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; + +/** + * + */ +@Component( role = ArtifactResolver.class, hint = "default" ) +public class DefaultArtifactResolver + implements ArtifactResolver, Contextualizable +{ + private PlexusContainer container; + + public Artifact resolveArtifact( ProjectBuildingRequest buildingRequest, Artifact mavenArtifact, + List<ArtifactRepository> remoteRepositories ) + throws ArtifactResolverException + { + try + { + String hint = isMaven31() ? "maven31" : "maven3"; + + ArtifactResolver effectiveArtifactResolver = container.lookup( ArtifactResolver.class, hint ); + + return effectiveArtifactResolver.resolveArtifact( buildingRequest, mavenArtifact, remoteRepositories ); + } + catch ( ComponentLookupException e ) + { + throw new ArtifactResolverException( e.getMessage(), e ); + } + } + + public void resolveTransitively( ProjectBuildingRequest buildingRequest, Artifact mavenArtifact, + List<ArtifactRepository> remoteRepositories ) + throws ArtifactResolverException + { + try + { + String hint = isMaven31() ? "maven31" : "maven3"; + + ArtifactResolver effectiveArtifactResolver = container.lookup( ArtifactResolver.class, hint ); + + effectiveArtifactResolver.resolveTransitively( buildingRequest, mavenArtifact, remoteRepositories ); + } + catch ( ComponentLookupException e ) + { + throw new ArtifactResolverException( e.getMessage(), e ); + } + } + + public void resolveTransitively( ProjectBuildingRequest buildingRequest, Artifact mavenArtifact, + List<ArtifactRepository> remoteRepositories, TransformableFilter filter ) + throws ArtifactResolverException + { + try + { + String hint = isMaven31() ? "maven31" : "maven3"; + + ArtifactResolver effectiveArtifactResolver = container.lookup( ArtifactResolver.class, hint ); + + effectiveArtifactResolver.resolveTransitively( buildingRequest, mavenArtifact, remoteRepositories, filter ); + } + catch ( ComponentLookupException e ) + { + throw new ArtifactResolverException( e.getMessage(), e ); + } + } + + /** + * @return true if the current Maven version is Maven 3.1. + */ + protected static boolean isMaven31() + { + return canFindCoreClass( "org.eclipse.aether.artifact.Artifact" ); // Maven 3.1 specific + } + + private static boolean canFindCoreClass( String className ) + { + try + { + Thread.currentThread().getContextClassLoader().loadClass( className ); + + return true; + } + catch ( ClassNotFoundException e ) + { + return false; + } + } + + /** + * Injects the Plexus content. + * + * @param context Plexus context to inject. + * @throws ContextException if the PlexusContainer could not be located. + */ + public void contextualize( Context context ) + throws ContextException + { + container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); + } + +} Modified: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/EclipseAetherFilterTransformer.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/EclipseAetherFilterTransformer.java?rev=1685372&r1=1685371&r2=1685372&view=diff ============================================================================== --- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/EclipseAetherFilterTransformer.java (original) +++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/EclipseAetherFilterTransformer.java Sun Jun 14 09:40:45 2015 @@ -1,83 +1,83 @@ -package org.apache.maven.shared.artifact.resolve.internal; - -/* - * 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.Collection; - -import org.apache.maven.shared.artifact.filter.resolve.AndFilter; -import org.apache.maven.shared.artifact.filter.resolve.ExclusionsFilter; -import org.apache.maven.shared.artifact.filter.resolve.FilterTransformer; -import org.apache.maven.shared.artifact.filter.resolve.OrFilter; -import org.apache.maven.shared.artifact.filter.resolve.PatternExclusionsFilter; -import org.apache.maven.shared.artifact.filter.resolve.PatternInclusionsFilter; -import org.apache.maven.shared.artifact.filter.resolve.ScopeFilter; -import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter; -import org.eclipse.aether.graph.DependencyFilter; -import org.eclipse.aether.util.filter.AndDependencyFilter; -import org.eclipse.aether.util.filter.ExclusionsDependencyFilter; -import org.eclipse.aether.util.filter.PatternExclusionsDependencyFilter; -import org.eclipse.aether.util.filter.PatternInclusionsDependencyFilter; -import org.eclipse.aether.util.filter.ScopeDependencyFilter; - -class EclipseAetherFilterTransformer - implements FilterTransformer<DependencyFilter> -{ - - public AndDependencyFilter transform( AndFilter andFilter ) - { - Collection<DependencyFilter> filters = new ArrayList<DependencyFilter>(); - for ( TransformableFilter filter : andFilter.getFilters() ) - { - filters.add( filter.transform( this ) ); - } - return new AndDependencyFilter( filters ); - } - - public ExclusionsDependencyFilter transform( ExclusionsFilter filter ) - { - return new ExclusionsDependencyFilter( filter.getExcludes() ); - } - - public AndDependencyFilter transform( OrFilter orFilter ) - { - Collection<DependencyFilter> filters = new ArrayList<DependencyFilter>(); - for ( TransformableFilter filter : orFilter.getFilters() ) - { - filters.add( filter.transform( this ) ); - } - return new AndDependencyFilter( filters ); - } - - public ScopeDependencyFilter transform( ScopeFilter filter ) - { - return new ScopeDependencyFilter( filter.getIncluded(), filter.getExcluded() ); - } - - public DependencyFilter transform( PatternExclusionsFilter filter ) - { - return new PatternExclusionsDependencyFilter( filter.getExcludes() ); - } - - public DependencyFilter transform( PatternInclusionsFilter filter ) - { - return new PatternInclusionsDependencyFilter( filter.getIncludes() ); - } -} +package org.apache.maven.shared.artifact.resolve.internal; + +/* + * 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.Collection; + +import org.apache.maven.shared.artifact.filter.resolve.AndFilter; +import org.apache.maven.shared.artifact.filter.resolve.ExclusionsFilter; +import org.apache.maven.shared.artifact.filter.resolve.FilterTransformer; +import org.apache.maven.shared.artifact.filter.resolve.OrFilter; +import org.apache.maven.shared.artifact.filter.resolve.PatternExclusionsFilter; +import org.apache.maven.shared.artifact.filter.resolve.PatternInclusionsFilter; +import org.apache.maven.shared.artifact.filter.resolve.ScopeFilter; +import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter; +import org.eclipse.aether.graph.DependencyFilter; +import org.eclipse.aether.util.filter.AndDependencyFilter; +import org.eclipse.aether.util.filter.ExclusionsDependencyFilter; +import org.eclipse.aether.util.filter.PatternExclusionsDependencyFilter; +import org.eclipse.aether.util.filter.PatternInclusionsDependencyFilter; +import org.eclipse.aether.util.filter.ScopeDependencyFilter; + +class EclipseAetherFilterTransformer + implements FilterTransformer<DependencyFilter> +{ + + public AndDependencyFilter transform( AndFilter andFilter ) + { + Collection<DependencyFilter> filters = new ArrayList<DependencyFilter>(); + for ( TransformableFilter filter : andFilter.getFilters() ) + { + filters.add( filter.transform( this ) ); + } + return new AndDependencyFilter( filters ); + } + + public ExclusionsDependencyFilter transform( ExclusionsFilter filter ) + { + return new ExclusionsDependencyFilter( filter.getExcludes() ); + } + + public AndDependencyFilter transform( OrFilter orFilter ) + { + Collection<DependencyFilter> filters = new ArrayList<DependencyFilter>(); + for ( TransformableFilter filter : orFilter.getFilters() ) + { + filters.add( filter.transform( this ) ); + } + return new AndDependencyFilter( filters ); + } + + public ScopeDependencyFilter transform( ScopeFilter filter ) + { + return new ScopeDependencyFilter( filter.getIncluded(), filter.getExcluded() ); + } + + public DependencyFilter transform( PatternExclusionsFilter filter ) + { + return new PatternExclusionsDependencyFilter( filter.getExcludes() ); + } + + public DependencyFilter transform( PatternInclusionsFilter filter ) + { + return new PatternInclusionsDependencyFilter( filter.getIncludes() ); + } +} Modified: maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/Maven30ArtifactResolver.java URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/Maven30ArtifactResolver.java?rev=1685372&r1=1685371&r2=1685372&view=diff ============================================================================== --- maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/Maven30ArtifactResolver.java (original) +++ maven/shared/trunk/maven-artifact-transfer/src/main/java/org/apache/maven/shared/artifact/resolve/internal/Maven30ArtifactResolver.java Sun Jun 14 09:40:45 2015 @@ -1,170 +1,170 @@ -package org.apache.maven.shared.artifact.resolve.internal; - -/* - * 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.Collection; -import java.util.List; - -import org.apache.maven.RepositoryUtils; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.project.ProjectBuildingRequest; -import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter; -import org.apache.maven.shared.artifact.resolve.ArtifactResolver; -import org.apache.maven.shared.artifact.resolve.ArtifactResolverException; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; -import org.sonatype.aether.RepositorySystem; -import org.sonatype.aether.RepositorySystemSession; -import org.sonatype.aether.artifact.Artifact; -import org.sonatype.aether.collection.CollectRequest; -import org.sonatype.aether.collection.DependencyCollectionException; -import org.sonatype.aether.graph.DependencyFilter; -import org.sonatype.aether.repository.RemoteRepository; -import org.sonatype.aether.resolution.ArtifactDescriptorException; -import org.sonatype.aether.resolution.ArtifactDescriptorRequest; -import org.sonatype.aether.resolution.ArtifactDescriptorResult; -import org.sonatype.aether.resolution.ArtifactRequest; -import org.sonatype.aether.resolution.ArtifactResolutionException; -import org.sonatype.aether.resolution.ArtifactResult; - -/** - * - */ -@Component( role = ArtifactResolver.class, hint = "maven3" ) -public class Maven30ArtifactResolver - implements ArtifactResolver -{ - @Requirement - private RepositorySystem repositorySystem; - - public org.apache.maven.artifact.Artifact resolveArtifact( ProjectBuildingRequest buildingRequest, - org.apache.maven.artifact.Artifact mavenArtifact, - List<ArtifactRepository> remoteRepositories ) - throws ArtifactResolverException - { - Artifact aetherArtifact = - (Artifact) Invoker.invoke( RepositoryUtils.class, "toArtifact", org.apache.maven.artifact.Artifact.class, - mavenArtifact ); - - @SuppressWarnings( "unchecked" ) - List<RemoteRepository> aetherRepositories = - (List<RemoteRepository>) Invoker.invoke( RepositoryUtils.class, "toRepos", List.class, remoteRepositories ); - - RepositorySystemSession session = - (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" ); - - try - { - // use descriptor to respect relocation - ArtifactDescriptorRequest descriptorRequest = - new ArtifactDescriptorRequest( aetherArtifact, aetherRepositories, null ); - - ArtifactDescriptorResult descriptorResult = - repositorySystem.readArtifactDescriptor( session, descriptorRequest ); - - ArtifactRequest request = new ArtifactRequest( descriptorResult.getArtifact(), aetherRepositories, null ); - - Artifact resolvedArtifact = repositorySystem.resolveArtifact( session, request ).getArtifact(); - - return (org.apache.maven.artifact.Artifact) Invoker.invoke( RepositoryUtils.class, "toArtifact", - Artifact.class, resolvedArtifact ); - } - catch ( ArtifactDescriptorException e ) - { - throw new ArtifactResolverException( e.getMessage(), e ); - } - catch ( ArtifactResolutionException e ) - { - throw new ArtifactResolverException( e.getMessage(), e ); - } - } - - public void resolveTransitively( ProjectBuildingRequest buildingRequest, - org.apache.maven.artifact.Artifact mavenArtifact, - List<ArtifactRepository> remoteRepositories ) - throws ArtifactResolverException - { - resolveTransitively( buildingRequest, mavenArtifact, remoteRepositories, null ); - } - - public void resolveTransitively( ProjectBuildingRequest buildingRequest, - org.apache.maven.artifact.Artifact mavenArtifact, - List<ArtifactRepository> remoteRepositories, - TransformableFilter dependencyFilter ) - throws ArtifactResolverException - { - Artifact aetherArtifact = - (Artifact) Invoker.invoke( RepositoryUtils.class, "toArtifact", org.apache.maven.artifact.Artifact.class, - mavenArtifact ); - - @SuppressWarnings( "unchecked" ) - List<RemoteRepository> aetherRepositories = - (List<RemoteRepository>) Invoker.invoke( RepositoryUtils.class, "toRepos", List.class, remoteRepositories ); - - RepositorySystemSession session = - (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" ); - - try - { - // use descriptor to respect relocation - ArtifactDescriptorRequest descriptorRequest = - new ArtifactDescriptorRequest( aetherArtifact, aetherRepositories, null ); - - ArtifactDescriptorResult descriptorResult = - repositorySystem.readArtifactDescriptor( session, descriptorRequest ); - - CollectRequest request = - new CollectRequest( descriptorResult.getDependencies(), descriptorResult.getManagedDependencies(), - aetherRepositories ); - - DependencyFilter depFilter = null; - if ( dependencyFilter != null ) - { - depFilter = dependencyFilter.transform( new SonatypeAetherFilterTransformer() ); - } - - List<ArtifactResult> artifactResults = repositorySystem.resolveDependencies( session, request, depFilter ); - - Collection<ArtifactRequest> artifactRequests = new ArrayList<ArtifactRequest>( 1 + artifactResults.size() ); - - artifactRequests.add( new ArtifactRequest( descriptorResult.getArtifact(), aetherRepositories, null ) ); - - for ( ArtifactResult artifactResult : artifactResults ) - { - artifactRequests.add( new ArtifactRequest( artifactResult.getArtifact(), aetherRepositories, null ) ); - } - - repositorySystem.resolveArtifacts( session, artifactRequests ); - } - catch ( ArtifactDescriptorException e ) - { - throw new ArtifactResolverException( e.getMessage(), e ); - } - catch ( ArtifactResolutionException e ) - { - throw new ArtifactResolverException( e.getMessage(), e ); - } - catch ( DependencyCollectionException e ) - { - throw new ArtifactResolverException( e.getMessage(), e ); - } - } -} +package org.apache.maven.shared.artifact.resolve.internal; + +/* + * 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.Collection; +import java.util.List; + +import org.apache.maven.RepositoryUtils; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.project.ProjectBuildingRequest; +import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter; +import org.apache.maven.shared.artifact.resolve.ArtifactResolver; +import org.apache.maven.shared.artifact.resolve.ArtifactResolverException; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; +import org.sonatype.aether.RepositorySystem; +import org.sonatype.aether.RepositorySystemSession; +import org.sonatype.aether.artifact.Artifact; +import org.sonatype.aether.collection.CollectRequest; +import org.sonatype.aether.collection.DependencyCollectionException; +import org.sonatype.aether.graph.DependencyFilter; +import org.sonatype.aether.repository.RemoteRepository; +import org.sonatype.aether.resolution.ArtifactDescriptorException; +import org.sonatype.aether.resolution.ArtifactDescriptorRequest; +import org.sonatype.aether.resolution.ArtifactDescriptorResult; +import org.sonatype.aether.resolution.ArtifactRequest; +import org.sonatype.aether.resolution.ArtifactResolutionException; +import org.sonatype.aether.resolution.ArtifactResult; + +/** + * + */ +@Component( role = ArtifactResolver.class, hint = "maven3" ) +public class Maven30ArtifactResolver + implements ArtifactResolver +{ + @Requirement + private RepositorySystem repositorySystem; + + public org.apache.maven.artifact.Artifact resolveArtifact( ProjectBuildingRequest buildingRequest, + org.apache.maven.artifact.Artifact mavenArtifact, + List<ArtifactRepository> remoteRepositories ) + throws ArtifactResolverException + { + Artifact aetherArtifact = + (Artifact) Invoker.invoke( RepositoryUtils.class, "toArtifact", org.apache.maven.artifact.Artifact.class, + mavenArtifact ); + + @SuppressWarnings( "unchecked" ) + List<RemoteRepository> aetherRepositories = + (List<RemoteRepository>) Invoker.invoke( RepositoryUtils.class, "toRepos", List.class, remoteRepositories ); + + RepositorySystemSession session = + (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" ); + + try + { + // use descriptor to respect relocation + ArtifactDescriptorRequest descriptorRequest = + new ArtifactDescriptorRequest( aetherArtifact, aetherRepositories, null ); + + ArtifactDescriptorResult descriptorResult = + repositorySystem.readArtifactDescriptor( session, descriptorRequest ); + + ArtifactRequest request = new ArtifactRequest( descriptorResult.getArtifact(), aetherRepositories, null ); + + Artifact resolvedArtifact = repositorySystem.resolveArtifact( session, request ).getArtifact(); + + return (org.apache.maven.artifact.Artifact) Invoker.invoke( RepositoryUtils.class, "toArtifact", + Artifact.class, resolvedArtifact ); + } + catch ( ArtifactDescriptorException e ) + { + throw new ArtifactResolverException( e.getMessage(), e ); + } + catch ( ArtifactResolutionException e ) + { + throw new ArtifactResolverException( e.getMessage(), e ); + } + } + + public void resolveTransitively( ProjectBuildingRequest buildingRequest, + org.apache.maven.artifact.Artifact mavenArtifact, + List<ArtifactRepository> remoteRepositories ) + throws ArtifactResolverException + { + resolveTransitively( buildingRequest, mavenArtifact, remoteRepositories, null ); + } + + public void resolveTransitively( ProjectBuildingRequest buildingRequest, + org.apache.maven.artifact.Artifact mavenArtifact, + List<ArtifactRepository> remoteRepositories, + TransformableFilter dependencyFilter ) + throws ArtifactResolverException + { + Artifact aetherArtifact = + (Artifact) Invoker.invoke( RepositoryUtils.class, "toArtifact", org.apache.maven.artifact.Artifact.class, + mavenArtifact ); + + @SuppressWarnings( "unchecked" ) + List<RemoteRepository> aetherRepositories = + (List<RemoteRepository>) Invoker.invoke( RepositoryUtils.class, "toRepos", List.class, remoteRepositories ); + + RepositorySystemSession session = + (RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" ); + + try + { + // use descriptor to respect relocation + ArtifactDescriptorRequest descriptorRequest = + new ArtifactDescriptorRequest( aetherArtifact, aetherRepositories, null ); + + ArtifactDescriptorResult descriptorResult = + repositorySystem.readArtifactDescriptor( session, descriptorRequest ); + + CollectRequest request = + new CollectRequest( descriptorResult.getDependencies(), descriptorResult.getManagedDependencies(), + aetherRepositories ); + + DependencyFilter depFilter = null; + if ( dependencyFilter != null ) + { + depFilter = dependencyFilter.transform( new SonatypeAetherFilterTransformer() ); + } + + List<ArtifactResult> artifactResults = repositorySystem.resolveDependencies( session, request, depFilter ); + + Collection<ArtifactRequest> artifactRequests = new ArrayList<ArtifactRequest>( 1 + artifactResults.size() ); + + artifactRequests.add( new ArtifactRequest( descriptorResult.getArtifact(), aetherRepositories, null ) ); + + for ( ArtifactResult artifactResult : artifactResults ) + { + artifactRequests.add( new ArtifactRequest( artifactResult.getArtifact(), aetherRepositories, null ) ); + } + + repositorySystem.resolveArtifacts( session, artifactRequests ); + } + catch ( ArtifactDescriptorException e ) + { + throw new ArtifactResolverException( e.getMessage(), e ); + } + catch ( ArtifactResolutionException e ) + { + throw new ArtifactResolverException( e.getMessage(), e ); + } + catch ( DependencyCollectionException e ) + { + throw new ArtifactResolverException( e.getMessage(), e ); + } + } +}