public static ArtifactRepository buildArtifactRepository( Repository repo, ArtifactRepositoryFactory artifactRepositoryFactory, PlexusContainer container ) throws InvalidRepositoryException { if ( repo != null ) { String id = repo.getId(); String url = repo.getUrl(); if ( id == null || id.trim().length() < 1 ) { throw new InvalidRepositoryException( "Repository ID must not be empty (URL is: " + url + ").", new IllegalArgumentException( "repository.id" ) ); } if ( url == null || url.trim().length() < 1 ) { throw new InvalidRepositoryException( "Repository URL must not be empty (ID is: " + id + ").", new IllegalArgumentException( "repository.url" ) ); } // TODO: make this a map inside the factory instead, so no lookup needed ArtifactRepositoryLayout layout = getRepositoryLayout( repo, container ); ArtifactRepositoryPolicy snapshots = buildArtifactRepositoryPolicy( repo.getSnapshots() ); ArtifactRepositoryPolicy releases = buildArtifactRepositoryPolicy( repo.getReleases() ); return artifactRepositoryFactory.createArtifactRepository( id, url, layout, snapshots, releases ); } else { return null; } }
@Deprecated public ArtifactRepository getMirrorRepository( ArtifactRepository repository ) { Mirror mirror = mirrorSelector.getMirror( repository, legacySupport.getSession().getSettings().getMirrors() ); if ( mirror != null ) { String id = mirror.getId(); if ( id == null ) { // TODO this should be illegal in settings.xml id = repository.getId(); } log.debug( "Using mirror: " + mirror.getUrl() + " (id: " + id + ")" ); repository = artifactRepositoryFactory.createArtifactRepository( id, mirror.getUrl(), repository.getLayout(), repository.getSnapshots(), repository.getReleases() ); } return repository; }
private ArtifactRepository getRepository( Settings settings ) { return artifactRepositoryFactory.createArtifactRepository( "local", "file://" + settings.getLocalRepository(), defaultRepositoryLayout, null, null ); }
private ArtifactRepository parseRepository(String repo, ArtifactRepositoryPolicy policy) throws MojoFailureException { // if it's a simple url String id = null; ArtifactRepositoryLayout layout = getLayout("default"); String url = repo; // if it's an extended repo URL of the form id::layout::url if (repo.contains("::")) { Matcher matcher = ALT_REPO_SYNTAX_PATTERN.matcher(repo); if (!matcher.matches()) { throw new MojoFailureException(repo, "Invalid syntax for repository: " + repo, "Invalid syntax for repository. Use \"id::layout::url\" or \"URL\"."); } id = matcher.group(1).trim(); if (!StringUtils.isEmpty(matcher.group(2))) { layout = getLayout(matcher.group(2).trim()); } url = matcher.group(3).trim(); } return artifactRepositoryFactory.createArtifactRepository(id, url, layout, policy, policy); }
/** * @param id * Repository ID. This ID has to match the ID in the repository index, due to a design bug in Maven. * @param indexDirectory * Directory that contains exploded index zip file. * @param repository * URL of the Maven repository. Used to resolve artifacts. */ public void addRemoteRepository(String id, File indexDirectory, URL repository) throws IOException, UnsupportedExistingLuceneIndexException { indexer.addIndexingContext(id, id,null, indexDirectory,null,null, NexusIndexer.DEFAULT_INDEX); remoteRepositories.add( arf.createArtifactRepository(id, repository.toExternalForm(), new DefaultRepositoryLayout(), POLICY, POLICY)); }
private ArtifactRepository getRepository( Settings settings ) { // ---------------------------------------------------------------------- // Set our configured location as the default but try to use the defaults // as returned by the MavenSettings component. // ---------------------------------------------------------------------- String localRepo = localRepository; if ( !( StringUtils.isEmpty( settings.getLocalRepository() ) ) ) { localRepo = settings.getLocalRepository(); } return artifactRepositoryFactory.createArtifactRepository( "local", "file://" + localRepo, repositoryLayout, null, null ); }
public static ArtifactRepository createRemoteRepository(MavenEmbedder embedder, String url, String id) { try { ArtifactRepositoryFactory fact = (ArtifactRepositoryFactory) embedder.getPlexusContainer().lookup(ArtifactRepositoryFactory.ROLE); ArtifactRepositoryPolicy snapshotsPolicy = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN); ArtifactRepositoryPolicy releasesPolicy = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN); return fact.createArtifactRepository(id, url, ArtifactRepositoryFactory.DEFAULT_LAYOUT_ID, snapshotsPolicy, releasesPolicy); } catch (UnknownRepositoryLayoutException ex) { Exceptions.printStackTrace(ex); } catch (ComponentLookupException ex) { Exceptions.printStackTrace(ex); } return null; }
public static ArtifactRepository createRemoteRepository(MavenEmbedder embedder, String url, String id) { try { ArtifactRepositoryFactory fact = (ArtifactRepositoryFactory) online.getPlexusContainer().lookup(ArtifactRepositoryFactory.ROLE); ArtifactRepositoryPolicy snapshotsPolicy = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN); ArtifactRepositoryPolicy releasesPolicy = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN); return fact.createArtifactRepository(id, url, ArtifactRepositoryFactory.DEFAULT_LAYOUT_ID, snapshotsPolicy, releasesPolicy); } catch (UnknownRepositoryLayoutException ex) { Exceptions.printStackTrace(ex); } catch (ComponentLookupException ex) { Exceptions.printStackTrace(ex); } return null; }
public ArtifactRepository createRepository( String url, String repositoryId ) throws ComponentLookupException { // snapshots vs releases // offline = to turning the update policy off //TODO: we'll need to allow finer grained creation of repositories but this will do for now String updatePolicyFlag = ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS; String checksumPolicyFlag = ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN; ArtifactRepositoryPolicy snapshotsPolicy = new ArtifactRepositoryPolicy( true, updatePolicyFlag, checksumPolicyFlag ); ArtifactRepositoryPolicy releasesPolicy = new ArtifactRepositoryPolicy( true, updatePolicyFlag, checksumPolicyFlag ); return artifactRepositoryFactory.createArtifactRepository( repositoryId, url, defaultArtifactRepositoryLayout, snapshotsPolicy, releasesPolicy ); }
public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered ) throws ConsumerException { repositoryLocation = repository.getLocation(); if ( generatedRepositoryLocation == null ) { generatedRepositoryLocation = new File( repositoryLocation ); } if ( localRepository == null ) { // This is a bit crappy, it would be better to operate entirely within // the base repository, but would need to adjust maven-artifact localRepository = new File( System.getProperty( "user.home" ), ".m2/repository" ); try { localArtifactRepository = artifactRepositoryFactory.createArtifactRepository( "local", localRepository.toURL().toExternalForm(), layout, null, null ); } catch ( MalformedURLException e ) { throw new ConsumerException( e.getMessage(), e ); } } }
/** * Code stealed from MavenArchetypeMojo * (org.apache.maven.plugins:maven-archetype-plugin:1.0-alpha4). */ public ArtifactRepository createRepository(String url, String repositoryId) { // snapshots vs releases // offline = to turning the update policy off // TODO: we'll need to allow finer grained creation of repositories but this will do for now String updatePolicyFlag=ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS; String checksumPolicyFlag=ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN; ArtifactRepositoryPolicy snapshotsPolicy=new ArtifactRepositoryPolicy(true, updatePolicyFlag, checksumPolicyFlag); ArtifactRepositoryPolicy releasesPolicy=new ArtifactRepositoryPolicy(true, updatePolicyFlag, checksumPolicyFlag); return artifactRepositoryFactory.createArtifactRepository(repositoryId, url, defaultArtifactRepositoryLayout, snapshotsPolicy, releasesPolicy); }
/** * Construct an ArtifactRepository instance that refers to the test-time Maven local repository. * @param localRepositoryDirectory The location of the local repository to be used for test builds. */ public ArtifactRepository createLocalArtifactRepositoryInstance( File localRepositoryDirectory ) throws TestToolsException { ArtifactRepositoryLayout defaultLayout; try { defaultLayout = (ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE, "default" ); } catch ( ComponentLookupException e ) { throw new TestToolsException( "Error retrieving default repository layout.", e ); } try { return repositoryFactory.createArtifactRepository( "local", localRepositoryDirectory.toURL() .toExternalForm(), defaultLayout, null, null ); } catch ( MalformedURLException e ) { throw new TestToolsException( "Error converting local repo directory to a URL.", e ); } }
/** * Construct an ArtifactRepository instance that refers to the test-time Maven local repository. * * @param localRepositoryDirectory The location of the local repository to be used for test builds. * @return an ArtifactRepository instance * @throws TestToolsException if any */ public ArtifactRepository createLocalArtifactRepositoryInstance( File localRepositoryDirectory ) throws TestToolsException { ArtifactRepositoryLayout defaultLayout; try { defaultLayout = (ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE, "default" ); } catch ( ComponentLookupException e ) { throw new TestToolsException( "Error retrieving default repository layout.", e ); } try { return repositoryFactory.createArtifactRepository( "local", localRepositoryDirectory.toURL() .toExternalForm(), defaultLayout, null, null ); } catch ( MalformedURLException e ) { throw new TestToolsException( "Error converting local repo directory to a URL.", e ); } }
public MavenRepositoryImpl() throws Exception { ClassWorld classWorld = new ClassWorld( "plexus.core", MavenRepositoryImpl.class.getClassLoader() ); ContainerConfiguration configuration = new DefaultContainerConfiguration().setClassWorld( classWorld ); plexus = new DefaultPlexusContainer( configuration ); ComponentDescriptor<ArtifactTransformationManager> componentDescriptor = plexus.getComponentDescriptor(ArtifactTransformationManager.class, ArtifactTransformationManager.class.getName(), "default"); if (componentDescriptor == null) { throw new IllegalArgumentException("Unable to find maven default ArtifactTransformationManager component. You might get this if you run the program from within the exec:java mojo."); } componentDescriptor.setImplementationClass(DefaultArtifactTransformationManager.class); indexer = plexus.lookup( NexusIndexer.class ); af = plexus.lookup(ArtifactFactory.class); ar = plexus.lookup(ArtifactResolver.class); arf = plexus.lookup(ArtifactRepositoryFactory.class); localRepo = new File(new File(System.getProperty("user.home")), ".m2/repository"); local = arf.createArtifactRepository("local", localRepo.toURI().toURL().toExternalForm(), new DefaultRepositoryLayout(), POLICY, POLICY); }
private ArtifactRepository getRepository( Settings settings ) { // ---------------------------------------------------------------------- // Set our configured location as the default but try to use the defaults // as returned by the MavenSettings component. // ---------------------------------------------------------------------- String localRepo = localRepository; if ( repository != null ) { return artifactRepositoryFactory.createArtifactRepository( repository.getName(), "file://" + repository.getLocation(), repositoryLayout, null, null ); } else if ( !( StringUtils.isEmpty( settings.getLocalRepository() ) ) ) { localRepo = settings.getLocalRepository(); } return artifactRepositoryFactory.createArtifactRepository( "local", "file://" + localRepo, repositoryLayout, null, null ); }
private void addP2Repository(File p2Repository, String p2PropertyName) throws UnknownRepositoryLayoutException { if (p2Repository == null || !p2Repository.exists() || !p2Repository.isDirectory()) return; if (p2Repository.list().length <= 0) { logger.debug("p2 repository '" + p2Repository.getAbsolutePath() + "' is empty. Skipping."); return; } if (artifactRepositoryFactory != null) { ArtifactRepository artifactRepository = artifactRepositoryFactory.createArtifactRepository( p2PropertyName, "file:///" + p2Repository, "p2", new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN), new ArtifactRepositoryPolicy(false, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN)); mavenProject.getRemoteArtifactRepositories().add(artifactRepository); session.getRequest().getRemoteRepositories().add(artifactRepository); } }
public void addRemoteRepository(final String id, final URI location) throws InvalidRepositoryException { assert id != null; assert location != null; try { ArtifactRepository repo = repositoryFactory.createArtifactRepository( id, location.toURL().toExternalForm(), ArtifactRepositoryFactory.DEFAULT_LAYOUT_ID, new ArtifactRepositoryPolicy(), // snapshots new ArtifactRepositoryPolicy()); // releases addRemoteRepository(repo); } catch (MalformedURLException e) { throw new InvalidRepositoryException(e.getMessage(), id, e); } } }
/** * using this method one creates an ArtifactRepository instance with injected mirrors and proxies * @param url * @param id * @return */ public ArtifactRepository createRemoteRepository(String url, String id) { setUpLegacySupport(); ArtifactRepositoryFactory fact = lookupComponent(ArtifactRepositoryFactory.class); assert fact!=null : "ArtifactRepositoryFactory component not found in maven"; ArtifactRepositoryPolicy snapshotsPolicy = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN); ArtifactRepositoryPolicy releasesPolicy = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN); return fact.createArtifactRepository(id, url, new DefaultRepositoryLayout(), snapshotsPolicy, releasesPolicy); }
public ArtifactRepository getMirrorRepository( ArtifactRepository repository ) { ArtifactRepository mirror = getMirror( repository ); if ( mirror != null ) { String id = mirror.getId(); if ( id == null ) { // TODO: this should be illegal in settings.xml id = repository.getId(); } getLogger().debug( "Using mirror: " + mirror.getUrl() + " (id: " + id + ")" ); repository = repositoryFactory.createArtifactRepository( id, mirror.getUrl(), repository.getLayout(), repository.getSnapshots(), repository.getReleases() ); } return repository; }
/** * Create a core-Maven ArtifactRepository from a Maven Ant Tasks's RemoteRepository definition. * @param repository the remote repository as defined in Ant * @return the corresponding ArtifactRepository */ protected ArtifactRepository createRemoteArtifactRepository( RemoteRepository repository ) { ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, repository.getLayout() ); ArtifactRepositoryFactory repositoryFactory = null; ArtifactRepository artifactRepository; try { repositoryFactory = getArtifactRepositoryFactory( repository ); ArtifactRepositoryPolicy snapshots = buildArtifactRepositoryPolicy( repository.getSnapshots() ); ArtifactRepositoryPolicy releases = buildArtifactRepositoryPolicy( repository.getReleases() ); artifactRepository = repositoryFactory.createArtifactRepository( repository.getId(), repository.getUrl(), repositoryLayout, snapshots, releases ); } finally { releaseArtifactRepositoryFactory( repositoryFactory ); } return artifactRepository; }