Cleaned up package structure
Project: http://git-wip-us.apache.org/repos/asf/maven-aether/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-aether/commit/c4d6f720 Tree: http://git-wip-us.apache.org/repos/asf/maven-aether/tree/c4d6f720 Diff: http://git-wip-us.apache.org/repos/asf/maven-aether/diff/c4d6f720 Branch: refs/heads/ant-tasks Commit: c4d6f72064c18ec689913a7cbb1a06f9bab92018 Parents: 1ec78d9 Author: Benjamin Bentmann <bentm...@sonatype.com> Authored: Wed Apr 30 01:58:10 2014 +0200 Committer: Benjamin Bentmann <bentm...@sonatype.com> Committed: Wed Apr 30 01:58:10 2014 +0200 ---------------------------------------------------------------------- .../aether/internal/ant/AetherUtils.java | 74 +++++++ .../eclipse/aether/internal/ant/AntRepoSys.java | 71 +++++- .../aether/internal/ant/ConverterUtils.java | 218 +++++++++++++++++++ .../aether/internal/ant/SettingsUtils.java | 173 +++++++++++++++ .../internal/ant/tasks/AbstractDistTask.java | 26 --- .../aether/internal/ant/tasks/Deploy.java | 27 +-- .../aether/internal/ant/tasks/Install.java | 21 +- .../aether/internal/ant/util/AetherUtils.java | 75 ------- .../internal/ant/util/ConverterUtils.java | 218 ------------------- .../aether/internal/ant/util/SettingsUtils.java | 173 --------------- 10 files changed, 535 insertions(+), 541 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-aether/blob/c4d6f720/src/main/java/org/eclipse/aether/internal/ant/AetherUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/eclipse/aether/internal/ant/AetherUtils.java b/src/main/java/org/eclipse/aether/internal/ant/AetherUtils.java new file mode 100644 index 0000000..e76ba08 --- /dev/null +++ b/src/main/java/org/eclipse/aether/internal/ant/AetherUtils.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2010, 2014 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.internal.ant; + +import java.io.File; + +import org.apache.tools.ant.Project; +import org.eclipse.aether.internal.ant.types.RemoteRepositories; + +class AetherUtils +{ + + public static File findGlobalSettings( Project project ) + { + File file = new File( new File( project.getProperty( "ant.home" ), "etc" ), Names.SETTINGS_XML ); + if ( file.isFile() ) + { + return file; + } + else + { + String mavenHome = getMavenHome( project ); + if ( mavenHome != null ) + { + return new File( new File( mavenHome, "conf" ), Names.SETTINGS_XML ); + } + } + + return null; + } + + public static String getMavenHome( Project project ) + { + String mavenHome = project.getProperty( "maven.home" ); + if ( mavenHome != null ) + { + return mavenHome; + } + return System.getenv( "M2_HOME" ); + } + + public static File findUserSettings( Project project ) + { + File userHome = new File( project.getProperty( "user.home" ) ); + File file = new File( new File( userHome, ".ant" ), Names.SETTINGS_XML ); + if ( file.isFile() ) + { + return file; + } + else + { + return new File( new File( userHome, ".m2" ), Names.SETTINGS_XML ); + } + } + + public static RemoteRepositories getDefaultRepositories( Project project ) + { + Object obj = project.getReference( Names.ID_DEFAULT_REPOS ); + if ( obj instanceof RemoteRepositories ) + { + return (RemoteRepositories) obj; + } + return null; + } + +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/c4d6f720/src/main/java/org/eclipse/aether/internal/ant/AntRepoSys.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/eclipse/aether/internal/ant/AntRepoSys.java b/src/main/java/org/eclipse/aether/internal/ant/AntRepoSys.java index 860b203..76cc927 100644 --- a/src/main/java/org/eclipse/aether/internal/ant/AntRepoSys.java +++ b/src/main/java/org/eclipse/aether/internal/ant/AntRepoSys.java @@ -56,12 +56,19 @@ 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.DefaultArtifact; import org.eclipse.aether.collection.CollectRequest; import org.eclipse.aether.collection.CollectResult; import org.eclipse.aether.collection.DependencyCollectionException; import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory; +import org.eclipse.aether.deployment.DeployRequest; +import org.eclipse.aether.deployment.DeploymentException; import org.eclipse.aether.impl.DefaultServiceLocator; import org.eclipse.aether.impl.RemoteRepositoryManager; +import org.eclipse.aether.installation.InstallRequest; +import org.eclipse.aether.installation.InstallationException; +import org.eclipse.aether.internal.ant.types.Artifact; +import org.eclipse.aether.internal.ant.types.Artifacts; import org.eclipse.aether.internal.ant.types.Authentication; import org.eclipse.aether.internal.ant.types.Dependencies; import org.eclipse.aether.internal.ant.types.Dependency; @@ -73,9 +80,6 @@ import org.eclipse.aether.internal.ant.types.Pom; import org.eclipse.aether.internal.ant.types.Proxy; import org.eclipse.aether.internal.ant.types.RemoteRepositories; import org.eclipse.aether.internal.ant.types.RemoteRepository; -import org.eclipse.aether.internal.ant.util.AetherUtils; -import org.eclipse.aether.internal.ant.util.ConverterUtils; -import org.eclipse.aether.internal.ant.util.SettingsUtils; import org.eclipse.aether.repository.AuthenticationSelector; import org.eclipse.aether.repository.LocalRepositoryManager; import org.eclipse.aether.repository.MirrorSelector; @@ -748,4 +752,65 @@ public class AntRepoSys return dependencies; } + public void install( Task task, Pom pom, Artifacts artifacts ) + { + RepositorySystemSession session = getSession( task, null ); + + InstallRequest request = new InstallRequest(); + request.setArtifacts( toArtifacts( task, session, pom, artifacts ) ); + + try + { + getSystem().install( session, request ); + } + catch ( InstallationException e ) + { + throw new BuildException( "Could not install artifacts: " + e.getMessage(), e ); + } + } + + public void deploy( Task task, Pom pom, Artifacts artifacts, RemoteRepository releaseRepository, + RemoteRepository snapshotRepository ) + { + RepositorySystemSession session = getSession( task, null ); + + DeployRequest request = new DeployRequest(); + request.setArtifacts( toArtifacts( task, session, pom, artifacts ) ); + boolean snapshot = request.getArtifacts().iterator().next().isSnapshot(); + RemoteRepository distRepo = ( snapshot && snapshotRepository != null ) ? snapshotRepository : releaseRepository; + request.setRepository( ConverterUtils.toDistRepository( distRepo, session ) ); + + try + { + getSystem().deploy( session, request ); + } + catch ( DeploymentException e ) + { + throw new BuildException( "Could not deploy artifacts: " + e.getMessage(), e ); + } + } + + private List<org.eclipse.aether.artifact.Artifact> toArtifacts( Task task, RepositorySystemSession session, + Pom pom, Artifacts artifacts ) + { + Model model = pom.getModel( task ); + File pomFile = pom.getFile(); + + List<org.eclipse.aether.artifact.Artifact> results = new ArrayList<org.eclipse.aether.artifact.Artifact>(); + + org.eclipse.aether.artifact.Artifact pomArtifact = + new DefaultArtifact( model.getGroupId(), model.getArtifactId(), "pom", model.getVersion() ).setFile( pomFile ); + results.add( pomArtifact ); + + for ( Artifact artifact : artifacts.getArtifacts() ) + { + org.eclipse.aether.artifact.Artifact buildArtifact = + new DefaultArtifact( model.getGroupId(), model.getArtifactId(), artifact.getClassifier(), + artifact.getType(), model.getVersion() ).setFile( artifact.getFile() ); + results.add( buildArtifact ); + } + + return results; + } + } http://git-wip-us.apache.org/repos/asf/maven-aether/blob/c4d6f720/src/main/java/org/eclipse/aether/internal/ant/ConverterUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/eclipse/aether/internal/ant/ConverterUtils.java b/src/main/java/org/eclipse/aether/internal/ant/ConverterUtils.java new file mode 100644 index 0000000..79f994b --- /dev/null +++ b/src/main/java/org/eclipse/aether/internal/ant/ConverterUtils.java @@ -0,0 +1,218 @@ +/******************************************************************************* + * Copyright (c) 2010, 2014 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.internal.ant; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.apache.tools.ant.Project; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.artifact.ArtifactProperties; +import org.eclipse.aether.artifact.ArtifactType; +import org.eclipse.aether.artifact.ArtifactTypeRegistry; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.artifact.DefaultArtifactType; +import org.eclipse.aether.impl.RemoteRepositoryManager; +import org.eclipse.aether.internal.ant.types.Authentication; +import org.eclipse.aether.internal.ant.types.Dependency; +import org.eclipse.aether.internal.ant.types.Exclusion; +import org.eclipse.aether.internal.ant.types.Proxy; +import org.eclipse.aether.internal.ant.types.RemoteRepositories; +import org.eclipse.aether.internal.ant.types.RemoteRepository; +import org.eclipse.aether.repository.RepositoryPolicy; +import org.eclipse.aether.util.repository.AuthenticationBuilder; + +/** + * Utility methods to convert between Aether and Ant objects. + */ +class ConverterUtils +{ + + private static org.eclipse.aether.artifact.Artifact toArtifact( Dependency dependency, ArtifactTypeRegistry types ) + { + ArtifactType type = types.get( dependency.getType() ); + if ( type == null ) + { + type = new DefaultArtifactType( dependency.getType() ); + } + + Map<String, String> props = null; + if ( "system".equals( dependency.getScope() ) && dependency.getSystemPath() != null ) + { + props = Collections.singletonMap( ArtifactProperties.LOCAL_PATH, dependency.getSystemPath().getPath() ); + } + + Artifact artifact = + new DefaultArtifact( dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier(), null, + dependency.getVersion(), props, type ); + + return artifact; + } + + public static org.eclipse.aether.repository.Authentication toAuthentication( Authentication auth ) + { + if ( auth == null ) + { + return null; + } + AuthenticationBuilder authBuilder = new AuthenticationBuilder(); + authBuilder.addUsername( auth.getUsername() ).addPassword( auth.getPassword() ); + authBuilder.addPrivateKey( auth.getPrivateKeyFile(), auth.getPassphrase() ); + return authBuilder.build(); + } + + public static org.eclipse.aether.graph.Dependency toDependency( Dependency dependency, List<Exclusion> exclusions, + RepositorySystemSession session ) + { + return new org.eclipse.aether.graph.Dependency( toArtifact( dependency, session.getArtifactTypeRegistry() ), + dependency.getScope(), false, + toExclusions( dependency.getExclusions(), exclusions ) ); + } + + /** + * Converts the given ant repository type to an Aether repository instance with authentication and proxy filled in + * via the sessions' selectors. + */ + public static org.eclipse.aether.repository.RemoteRepository toDistRepository( RemoteRepository repo, + RepositorySystemSession session ) + { + org.eclipse.aether.repository.RemoteRepository result = toRepository( repo ); + org.eclipse.aether.repository.RemoteRepository.Builder builder = + new org.eclipse.aether.repository.RemoteRepository.Builder( result ); + builder.setAuthentication( session.getAuthenticationSelector().getAuthentication( result ) ); + builder.setProxy( session.getProxySelector().getProxy( result ) ); + return builder.build(); + } + + private static org.eclipse.aether.graph.Exclusion toExclusion( Exclusion exclusion ) + { + return new org.eclipse.aether.graph.Exclusion( exclusion.getGroupId(), exclusion.getArtifactId(), + exclusion.getClassifier(), exclusion.getExtension() ); + } + + private static Collection<org.eclipse.aether.graph.Exclusion> toExclusions( Collection<Exclusion> exclusions1, + Collection<Exclusion> exclusions2 ) + { + Collection<org.eclipse.aether.graph.Exclusion> results = + new LinkedHashSet<org.eclipse.aether.graph.Exclusion>(); + if ( exclusions1 != null ) + { + for ( Exclusion exclusion : exclusions1 ) + { + results.add( toExclusion( exclusion ) ); + } + } + if ( exclusions2 != null ) + { + for ( Exclusion exclusion : exclusions2 ) + { + results.add( toExclusion( exclusion ) ); + } + } + return results; + } + + private static RepositoryPolicy toPolicy( RemoteRepository.Policy policy, boolean enabled, String updates, + String checksums ) + { + if ( policy != null ) + { + enabled = policy.isEnabled(); + if ( policy.getChecksums() != null ) + { + checksums = policy.getChecksums(); + } + if ( policy.getUpdates() != null ) + { + updates = policy.getUpdates(); + } + } + return new RepositoryPolicy( enabled, updates, checksums ); + } + + /** + * Adds every <String, String>-entry in the map as a property to the given Properties. + */ + public static Properties addProperties( Properties props, Map<?, ?> map ) + { + if ( props == null ) + { + props = new Properties(); + } + for ( Map.Entry<?, ?> entry : map.entrySet() ) + { + if ( entry.getKey() instanceof String && entry.getValue() instanceof String ) + { + props.put( entry.getKey(), entry.getValue() ); + } + } + return props; + } + + public static org.eclipse.aether.repository.Proxy toProxy( Proxy proxy ) + { + if ( proxy == null ) + { + return null; + } + return new org.eclipse.aether.repository.Proxy( proxy.getType(), proxy.getHost(), proxy.getPort(), + toAuthentication( proxy.getAuthentication() ) ); + } + + private static org.eclipse.aether.repository.RemoteRepository toRepository( RemoteRepository repo ) + { + org.eclipse.aether.repository.RemoteRepository.Builder builder = + new org.eclipse.aether.repository.RemoteRepository.Builder( repo.getId(), repo.getType(), repo.getUrl() ); + builder.setSnapshotPolicy( toPolicy( repo.getSnapshotPolicy(), repo.isSnapshots(), repo.getUpdates(), + repo.getChecksums() ) ); + builder.setReleasePolicy( toPolicy( repo.getReleasePolicy(), repo.isReleases(), repo.getUpdates(), + repo.getChecksums() ) ); + builder.setAuthentication( toAuthentication( repo.getAuthentication() ) ); + return builder.build(); + } + + public static List<org.eclipse.aether.repository.RemoteRepository> toRepositories( Project project, + RepositorySystemSession session, + RemoteRepositories repos, RemoteRepositoryManager remoteRepositoryManager ) + { + List<RemoteRepository> repositories; + + if ( repos != null ) + { + repositories = repos.getRepositories(); + } + else + { + repositories = new ArrayList<RemoteRepository>(); + } + + List<org.eclipse.aether.repository.RemoteRepository> results = + new ArrayList<org.eclipse.aether.repository.RemoteRepository>(); + for ( RemoteRepository repo : repositories ) + { + results.add( toRepository( repo ) ); + } + + results = + remoteRepositoryManager.aggregateRepositories( session, + Collections.<org.eclipse.aether.repository.RemoteRepository> emptyList(), + results, true ); + + return results; + } + +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/c4d6f720/src/main/java/org/eclipse/aether/internal/ant/SettingsUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/eclipse/aether/internal/ant/SettingsUtils.java b/src/main/java/org/eclipse/aether/internal/ant/SettingsUtils.java new file mode 100644 index 0000000..1d7314c --- /dev/null +++ b/src/main/java/org/eclipse/aether/internal/ant/SettingsUtils.java @@ -0,0 +1,173 @@ +/******************************************************************************* + * Copyright (c) 2010, 2014 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.internal.ant; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.settings.Activation; +import org.apache.maven.settings.ActivationFile; +import org.apache.maven.settings.ActivationOS; +import org.apache.maven.settings.ActivationProperty; +import org.apache.maven.settings.Profile; +import org.apache.maven.settings.Repository; +import org.apache.maven.settings.RepositoryPolicy; + +/** + * Utility methods to read settings from Mavens settings.xml. + */ +class SettingsUtils +{ + + public static List<org.apache.maven.model.Profile> convert( List<Profile> profiles ) + { + if ( profiles == null ) + { + return null; + } + + List<org.apache.maven.model.Profile> results = new ArrayList<org.apache.maven.model.Profile>(); + + for ( Profile profile : profiles ) + { + results.add( convert( profile ) ); + } + + return results; + } + + static org.apache.maven.model.Profile convert( Profile profile ) + { + if ( profile == null ) + { + return null; + } + + org.apache.maven.model.Profile result = new org.apache.maven.model.Profile(); + + result.setId( profile.getId() ); + result.setProperties( profile.getProperties() ); + result.setSource( "settings.xml" ); + result.setActivation( convert( profile.getActivation() ) ); + + for ( Repository repo : profile.getRepositories() ) + { + result.addRepository( convert( repo ) ); + } + + for ( Repository repo : profile.getPluginRepositories() ) + { + result.addPluginRepository( convert( repo ) ); + } + + return result; + } + + static org.apache.maven.model.Activation convert( Activation activation ) + { + if ( activation == null ) + { + return null; + } + + org.apache.maven.model.Activation result = new org.apache.maven.model.Activation(); + + result.setActiveByDefault( activation.isActiveByDefault() ); + result.setJdk( activation.getJdk() ); + result.setFile( convert( activation.getFile() ) ); + result.setProperty( convert( activation.getProperty() ) ); + result.setOs( convert( activation.getOs() ) ); + + return result; + } + + static org.apache.maven.model.ActivationOS convert( ActivationOS activation ) + { + if ( activation == null ) + { + return null; + } + + org.apache.maven.model.ActivationOS result = new org.apache.maven.model.ActivationOS(); + + result.setArch( activation.getArch() ); + result.setFamily( activation.getFamily() ); + result.setName( activation.getName() ); + result.setVersion( activation.getVersion() ); + + return result; + } + + static org.apache.maven.model.ActivationProperty convert( ActivationProperty activation ) + { + if ( activation == null ) + { + return null; + } + + org.apache.maven.model.ActivationProperty result = new org.apache.maven.model.ActivationProperty(); + + result.setName( activation.getName() ); + result.setValue( activation.getValue() ); + + return result; + } + + static org.apache.maven.model.ActivationFile convert( ActivationFile activation ) + { + if ( activation == null ) + { + return null; + } + + org.apache.maven.model.ActivationFile result = new org.apache.maven.model.ActivationFile(); + + result.setExists( activation.getExists() ); + result.setMissing( activation.getMissing() ); + + return result; + } + + static org.apache.maven.model.Repository convert( Repository repo ) + { + if ( repo == null ) + { + return null; + } + + org.apache.maven.model.Repository result = new org.apache.maven.model.Repository(); + + result.setId( repo.getId() ); + result.setUrl( repo.getUrl() ); + result.setLayout( repo.getLayout() ); + result.setReleases( convert( repo.getReleases() ) ); + result.setSnapshots( convert( repo.getSnapshots() ) ); + + return result; + } + + static org.apache.maven.model.RepositoryPolicy convert( RepositoryPolicy policy ) + { + if ( policy == null ) + { + return null; + } + + org.apache.maven.model.RepositoryPolicy result = new org.apache.maven.model.RepositoryPolicy(); + + result.setEnabled( policy.isEnabled() ); + result.setChecksumPolicy( policy.getChecksumPolicy() ); + result.setUpdatePolicy( policy.getUpdatePolicy() ); + + return result; + } + +} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/c4d6f720/src/main/java/org/eclipse/aether/internal/ant/tasks/AbstractDistTask.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/eclipse/aether/internal/ant/tasks/AbstractDistTask.java b/src/main/java/org/eclipse/aether/internal/ant/tasks/AbstractDistTask.java index 215b6e6..1c0eccb 100644 --- a/src/main/java/org/eclipse/aether/internal/ant/tasks/AbstractDistTask.java +++ b/src/main/java/org/eclipse/aether/internal/ant/tasks/AbstractDistTask.java @@ -11,9 +11,7 @@ package org.eclipse.aether.internal.ant.tasks; import java.io.File; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.apache.maven.model.Model; @@ -21,12 +19,10 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.types.Reference; -import org.eclipse.aether.artifact.DefaultArtifact; import org.eclipse.aether.internal.ant.AntRepoSys; import org.eclipse.aether.internal.ant.types.Artifact; import org.eclipse.aether.internal.ant.types.Artifacts; import org.eclipse.aether.internal.ant.types.Pom; -import org.eclipse.aether.RepositorySystemSession; /** */ @@ -114,28 +110,6 @@ public abstract class AbstractDistTask } } - protected List<org.eclipse.aether.artifact.Artifact> toArtifacts( RepositorySystemSession session ) - { - Model model = getPom().getModel( this ); - File pomFile = getPom().getFile(); - - List<org.eclipse.aether.artifact.Artifact> results = new ArrayList<org.eclipse.aether.artifact.Artifact>(); - - org.eclipse.aether.artifact.Artifact pomArtifact = - new DefaultArtifact( model.getGroupId(), model.getArtifactId(), "pom", model.getVersion() ).setFile( pomFile ); - results.add( pomArtifact ); - - for ( Artifact artifact : getArtifacts().getArtifacts() ) - { - org.eclipse.aether.artifact.Artifact buildArtifact = - new DefaultArtifact( model.getGroupId(), model.getArtifactId(), artifact.getClassifier(), - artifact.getType(), model.getVersion() ).setFile( artifact.getFile() ); - results.add( buildArtifact ); - } - - return results; - } - protected Artifacts getArtifacts() { if ( artifacts == null ) http://git-wip-us.apache.org/repos/asf/maven-aether/blob/c4d6f720/src/main/java/org/eclipse/aether/internal/ant/tasks/Deploy.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/eclipse/aether/internal/ant/tasks/Deploy.java b/src/main/java/org/eclipse/aether/internal/ant/tasks/Deploy.java index fdf8a83..7f72919 100644 --- a/src/main/java/org/eclipse/aether/internal/ant/tasks/Deploy.java +++ b/src/main/java/org/eclipse/aether/internal/ant/tasks/Deploy.java @@ -12,13 +12,8 @@ package org.eclipse.aether.internal.ant.tasks; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.types.Reference; -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.deployment.DeployRequest; -import org.eclipse.aether.deployment.DeploymentException; import org.eclipse.aether.internal.ant.AntRepoSys; import org.eclipse.aether.internal.ant.types.RemoteRepository; -import org.eclipse.aether.internal.ant.util.ConverterUtils; /** */ @@ -94,27 +89,7 @@ public class Deploy { validate(); - AntRepoSys sys = AntRepoSys.getInstance( getProject() ); - - RepositorySystemSession session = sys.getSession( this, null ); - RepositorySystem system = sys.getSystem(); - - DeployRequest request = new DeployRequest(); - - request.setArtifacts( toArtifacts( session ) ); - - boolean snapshot = request.getArtifacts().iterator().next().isSnapshot(); - RemoteRepository distRepo = ( snapshot && snapshotRepository != null ) ? snapshotRepository : repository; - request.setRepository( ConverterUtils.toDistRepository( distRepo, session ) ); - - try - { - system.deploy( session, request ); - } - catch ( DeploymentException e ) - { - throw new BuildException( "Could not deploy artifacts: " + e.getMessage(), e ); - } + AntRepoSys.getInstance( getProject() ).deploy( this, getPom(), getArtifacts(), repository, snapshotRepository ); } } http://git-wip-us.apache.org/repos/asf/maven-aether/blob/c4d6f720/src/main/java/org/eclipse/aether/internal/ant/tasks/Install.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/eclipse/aether/internal/ant/tasks/Install.java b/src/main/java/org/eclipse/aether/internal/ant/tasks/Install.java index 2029c8a..2a30359 100644 --- a/src/main/java/org/eclipse/aether/internal/ant/tasks/Install.java +++ b/src/main/java/org/eclipse/aether/internal/ant/tasks/Install.java @@ -11,10 +11,6 @@ package org.eclipse.aether.internal.ant.tasks; import org.apache.tools.ant.BuildException; -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.installation.InstallRequest; -import org.eclipse.aether.installation.InstallationException; import org.eclipse.aether.internal.ant.AntRepoSys; /** @@ -29,22 +25,7 @@ public class Install { validate(); - AntRepoSys sys = AntRepoSys.getInstance( getProject() ); - - RepositorySystemSession session = sys.getSession( this, null ); - RepositorySystem system = sys.getSystem(); - - InstallRequest request = new InstallRequest(); - request.setArtifacts( toArtifacts( session ) ); - - try - { - system.install( session, request ); - } - catch ( InstallationException e ) - { - throw new BuildException( "Could not install artifacts: " + e.getMessage(), e ); - } + AntRepoSys.getInstance( getProject() ).install( this, getPom(), getArtifacts() ); } } http://git-wip-us.apache.org/repos/asf/maven-aether/blob/c4d6f720/src/main/java/org/eclipse/aether/internal/ant/util/AetherUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/eclipse/aether/internal/ant/util/AetherUtils.java b/src/main/java/org/eclipse/aether/internal/ant/util/AetherUtils.java deleted file mode 100644 index 16c4db4..0000000 --- a/src/main/java/org/eclipse/aether/internal/ant/util/AetherUtils.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2014 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.internal.ant.util; - -import java.io.File; - -import org.apache.tools.ant.Project; -import org.eclipse.aether.internal.ant.Names; -import org.eclipse.aether.internal.ant.types.RemoteRepositories; - -public class AetherUtils -{ - - public static File findGlobalSettings( Project project ) - { - File file = new File( new File( project.getProperty( "ant.home" ), "etc" ), Names.SETTINGS_XML ); - if ( file.isFile() ) - { - return file; - } - else - { - String mavenHome = getMavenHome( project ); - if ( mavenHome != null ) - { - return new File( new File( mavenHome, "conf" ), Names.SETTINGS_XML ); - } - } - - return null; - } - - public static String getMavenHome( Project project ) - { - String mavenHome = project.getProperty( "maven.home" ); - if ( mavenHome != null ) - { - return mavenHome; - } - return System.getenv( "M2_HOME" ); - } - - public static File findUserSettings( Project project ) - { - File userHome = new File( project.getProperty( "user.home" ) ); - File file = new File( new File( userHome, ".ant" ), Names.SETTINGS_XML ); - if ( file.isFile() ) - { - return file; - } - else - { - return new File( new File( userHome, ".m2" ), Names.SETTINGS_XML ); - } - } - - public static RemoteRepositories getDefaultRepositories( Project project ) - { - Object obj = project.getReference( Names.ID_DEFAULT_REPOS ); - if ( obj instanceof RemoteRepositories ) - { - return (RemoteRepositories) obj; - } - return null; - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/c4d6f720/src/main/java/org/eclipse/aether/internal/ant/util/ConverterUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/eclipse/aether/internal/ant/util/ConverterUtils.java b/src/main/java/org/eclipse/aether/internal/ant/util/ConverterUtils.java deleted file mode 100644 index 3c604c4..0000000 --- a/src/main/java/org/eclipse/aether/internal/ant/util/ConverterUtils.java +++ /dev/null @@ -1,218 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2014 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.internal.ant.util; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import org.apache.tools.ant.Project; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.artifact.ArtifactProperties; -import org.eclipse.aether.artifact.ArtifactType; -import org.eclipse.aether.artifact.ArtifactTypeRegistry; -import org.eclipse.aether.artifact.DefaultArtifact; -import org.eclipse.aether.artifact.DefaultArtifactType; -import org.eclipse.aether.impl.RemoteRepositoryManager; -import org.eclipse.aether.internal.ant.types.Authentication; -import org.eclipse.aether.internal.ant.types.Dependency; -import org.eclipse.aether.internal.ant.types.Exclusion; -import org.eclipse.aether.internal.ant.types.Proxy; -import org.eclipse.aether.internal.ant.types.RemoteRepositories; -import org.eclipse.aether.internal.ant.types.RemoteRepository; -import org.eclipse.aether.repository.RepositoryPolicy; -import org.eclipse.aether.util.repository.AuthenticationBuilder; - -/** - * Utility methods to convert between Aether and Ant objects. - */ -public class ConverterUtils -{ - - private static org.eclipse.aether.artifact.Artifact toArtifact( Dependency dependency, ArtifactTypeRegistry types ) - { - ArtifactType type = types.get( dependency.getType() ); - if ( type == null ) - { - type = new DefaultArtifactType( dependency.getType() ); - } - - Map<String, String> props = null; - if ( "system".equals( dependency.getScope() ) && dependency.getSystemPath() != null ) - { - props = Collections.singletonMap( ArtifactProperties.LOCAL_PATH, dependency.getSystemPath().getPath() ); - } - - Artifact artifact = - new DefaultArtifact( dependency.getGroupId(), dependency.getArtifactId(), dependency.getClassifier(), null, - dependency.getVersion(), props, type ); - - return artifact; - } - - public static org.eclipse.aether.repository.Authentication toAuthentication( Authentication auth ) - { - if ( auth == null ) - { - return null; - } - AuthenticationBuilder authBuilder = new AuthenticationBuilder(); - authBuilder.addUsername( auth.getUsername() ).addPassword( auth.getPassword() ); - authBuilder.addPrivateKey( auth.getPrivateKeyFile(), auth.getPassphrase() ); - return authBuilder.build(); - } - - public static org.eclipse.aether.graph.Dependency toDependency( Dependency dependency, List<Exclusion> exclusions, - RepositorySystemSession session ) - { - return new org.eclipse.aether.graph.Dependency( toArtifact( dependency, session.getArtifactTypeRegistry() ), - dependency.getScope(), false, - toExclusions( dependency.getExclusions(), exclusions ) ); - } - - /** - * Converts the given ant repository type to an Aether repository instance with authentication and proxy filled in - * via the sessions' selectors. - */ - public static org.eclipse.aether.repository.RemoteRepository toDistRepository( RemoteRepository repo, - RepositorySystemSession session ) - { - org.eclipse.aether.repository.RemoteRepository result = toRepository( repo ); - org.eclipse.aether.repository.RemoteRepository.Builder builder = - new org.eclipse.aether.repository.RemoteRepository.Builder( result ); - builder.setAuthentication( session.getAuthenticationSelector().getAuthentication( result ) ); - builder.setProxy( session.getProxySelector().getProxy( result ) ); - return builder.build(); - } - - private static org.eclipse.aether.graph.Exclusion toExclusion( Exclusion exclusion ) - { - return new org.eclipse.aether.graph.Exclusion( exclusion.getGroupId(), exclusion.getArtifactId(), - exclusion.getClassifier(), exclusion.getExtension() ); - } - - private static Collection<org.eclipse.aether.graph.Exclusion> toExclusions( Collection<Exclusion> exclusions1, - Collection<Exclusion> exclusions2 ) - { - Collection<org.eclipse.aether.graph.Exclusion> results = - new LinkedHashSet<org.eclipse.aether.graph.Exclusion>(); - if ( exclusions1 != null ) - { - for ( Exclusion exclusion : exclusions1 ) - { - results.add( toExclusion( exclusion ) ); - } - } - if ( exclusions2 != null ) - { - for ( Exclusion exclusion : exclusions2 ) - { - results.add( toExclusion( exclusion ) ); - } - } - return results; - } - - private static RepositoryPolicy toPolicy( RemoteRepository.Policy policy, boolean enabled, String updates, - String checksums ) - { - if ( policy != null ) - { - enabled = policy.isEnabled(); - if ( policy.getChecksums() != null ) - { - checksums = policy.getChecksums(); - } - if ( policy.getUpdates() != null ) - { - updates = policy.getUpdates(); - } - } - return new RepositoryPolicy( enabled, updates, checksums ); - } - - /** - * Adds every <String, String>-entry in the map as a property to the given Properties. - */ - public static Properties addProperties( Properties props, Map<?, ?> map ) - { - if ( props == null ) - { - props = new Properties(); - } - for ( Map.Entry<?, ?> entry : map.entrySet() ) - { - if ( entry.getKey() instanceof String && entry.getValue() instanceof String ) - { - props.put( entry.getKey(), entry.getValue() ); - } - } - return props; - } - - public static org.eclipse.aether.repository.Proxy toProxy( Proxy proxy ) - { - if ( proxy == null ) - { - return null; - } - return new org.eclipse.aether.repository.Proxy( proxy.getType(), proxy.getHost(), proxy.getPort(), - toAuthentication( proxy.getAuthentication() ) ); - } - - private static org.eclipse.aether.repository.RemoteRepository toRepository( RemoteRepository repo ) - { - org.eclipse.aether.repository.RemoteRepository.Builder builder = - new org.eclipse.aether.repository.RemoteRepository.Builder( repo.getId(), repo.getType(), repo.getUrl() ); - builder.setSnapshotPolicy( toPolicy( repo.getSnapshotPolicy(), repo.isSnapshots(), repo.getUpdates(), - repo.getChecksums() ) ); - builder.setReleasePolicy( toPolicy( repo.getReleasePolicy(), repo.isReleases(), repo.getUpdates(), - repo.getChecksums() ) ); - builder.setAuthentication( toAuthentication( repo.getAuthentication() ) ); - return builder.build(); - } - - public static List<org.eclipse.aether.repository.RemoteRepository> toRepositories( Project project, - RepositorySystemSession session, - RemoteRepositories repos, RemoteRepositoryManager remoteRepositoryManager ) - { - List<RemoteRepository> repositories; - - if ( repos != null ) - { - repositories = repos.getRepositories(); - } - else - { - repositories = new ArrayList<RemoteRepository>(); - } - - List<org.eclipse.aether.repository.RemoteRepository> results = - new ArrayList<org.eclipse.aether.repository.RemoteRepository>(); - for ( RemoteRepository repo : repositories ) - { - results.add( toRepository( repo ) ); - } - - results = - remoteRepositoryManager.aggregateRepositories( session, - Collections.<org.eclipse.aether.repository.RemoteRepository> emptyList(), - results, true ); - - return results; - } - -} http://git-wip-us.apache.org/repos/asf/maven-aether/blob/c4d6f720/src/main/java/org/eclipse/aether/internal/ant/util/SettingsUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/eclipse/aether/internal/ant/util/SettingsUtils.java b/src/main/java/org/eclipse/aether/internal/ant/util/SettingsUtils.java deleted file mode 100644 index 5fe44bf..0000000 --- a/src/main/java/org/eclipse/aether/internal/ant/util/SettingsUtils.java +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010, 2014 Sonatype, Inc. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Sonatype, Inc. - initial API and implementation - *******************************************************************************/ -package org.eclipse.aether.internal.ant.util; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.maven.settings.Activation; -import org.apache.maven.settings.ActivationFile; -import org.apache.maven.settings.ActivationOS; -import org.apache.maven.settings.ActivationProperty; -import org.apache.maven.settings.Profile; -import org.apache.maven.settings.Repository; -import org.apache.maven.settings.RepositoryPolicy; - -/** - * Utility methods to read settings from Mavens settings.xml. - */ -public class SettingsUtils -{ - - public static List<org.apache.maven.model.Profile> convert( List<Profile> profiles ) - { - if ( profiles == null ) - { - return null; - } - - List<org.apache.maven.model.Profile> results = new ArrayList<org.apache.maven.model.Profile>(); - - for ( Profile profile : profiles ) - { - results.add( convert( profile ) ); - } - - return results; - } - - static org.apache.maven.model.Profile convert( Profile profile ) - { - if ( profile == null ) - { - return null; - } - - org.apache.maven.model.Profile result = new org.apache.maven.model.Profile(); - - result.setId( profile.getId() ); - result.setProperties( profile.getProperties() ); - result.setSource( "settings.xml" ); - result.setActivation( convert( profile.getActivation() ) ); - - for ( Repository repo : profile.getRepositories() ) - { - result.addRepository( convert( repo ) ); - } - - for ( Repository repo : profile.getPluginRepositories() ) - { - result.addPluginRepository( convert( repo ) ); - } - - return result; - } - - static org.apache.maven.model.Activation convert( Activation activation ) - { - if ( activation == null ) - { - return null; - } - - org.apache.maven.model.Activation result = new org.apache.maven.model.Activation(); - - result.setActiveByDefault( activation.isActiveByDefault() ); - result.setJdk( activation.getJdk() ); - result.setFile( convert( activation.getFile() ) ); - result.setProperty( convert( activation.getProperty() ) ); - result.setOs( convert( activation.getOs() ) ); - - return result; - } - - static org.apache.maven.model.ActivationOS convert( ActivationOS activation ) - { - if ( activation == null ) - { - return null; - } - - org.apache.maven.model.ActivationOS result = new org.apache.maven.model.ActivationOS(); - - result.setArch( activation.getArch() ); - result.setFamily( activation.getFamily() ); - result.setName( activation.getName() ); - result.setVersion( activation.getVersion() ); - - return result; - } - - static org.apache.maven.model.ActivationProperty convert( ActivationProperty activation ) - { - if ( activation == null ) - { - return null; - } - - org.apache.maven.model.ActivationProperty result = new org.apache.maven.model.ActivationProperty(); - - result.setName( activation.getName() ); - result.setValue( activation.getValue() ); - - return result; - } - - static org.apache.maven.model.ActivationFile convert( ActivationFile activation ) - { - if ( activation == null ) - { - return null; - } - - org.apache.maven.model.ActivationFile result = new org.apache.maven.model.ActivationFile(); - - result.setExists( activation.getExists() ); - result.setMissing( activation.getMissing() ); - - return result; - } - - static org.apache.maven.model.Repository convert( Repository repo ) - { - if ( repo == null ) - { - return null; - } - - org.apache.maven.model.Repository result = new org.apache.maven.model.Repository(); - - result.setId( repo.getId() ); - result.setUrl( repo.getUrl() ); - result.setLayout( repo.getLayout() ); - result.setReleases( convert( repo.getReleases() ) ); - result.setSnapshots( convert( repo.getSnapshots() ) ); - - return result; - } - - static org.apache.maven.model.RepositoryPolicy convert( RepositoryPolicy policy ) - { - if ( policy == null ) - { - return null; - } - - org.apache.maven.model.RepositoryPolicy result = new org.apache.maven.model.RepositoryPolicy(); - - result.setEnabled( policy.isEnabled() ); - result.setChecksumPolicy( policy.getChecksumPolicy() ); - result.setUpdatePolicy( policy.getUpdatePolicy() ); - - return result; - } - -}