List of usage examples for org.apache.maven.artifact.repository DefaultArtifactRepository DefaultArtifactRepository
public DefaultArtifactRepository(String id, String url, ArtifactRepositoryLayout layout)
From source file:com.adviser.maven.MojoSupport.java
License:Apache License
protected Artifact resourceToArtifact(String resourceLocation, boolean skipNonMavenProtocols) throws MojoExecutionException { resourceLocation = resourceLocation.replace("\r\n", "").replace("\n", "").replace(" ", "").replace("\t", "");//from w ww .ja v a2 s. c o m final int index = resourceLocation.indexOf("mvn:"); if (index < 0) { if (skipNonMavenProtocols) { return null; } throw new MojoExecutionException("Resource URL is not a maven URL: " + resourceLocation); } else { resourceLocation = resourceLocation.substring(index + "mvn:".length()); } // Truncate the URL when a '#', a '?' or a '$' is encountered final int index1 = resourceLocation.indexOf('?'); final int index2 = resourceLocation.indexOf('#'); int endIndex = -1; if (index1 > 0) { if (index2 > 0) { endIndex = Math.min(index1, index2); } else { endIndex = index1; } } else if (index2 > 0) { endIndex = index2; } if (endIndex >= 0) { resourceLocation = resourceLocation.substring(0, endIndex); } final int index3 = resourceLocation.indexOf('$'); if (index3 > 0) { resourceLocation = resourceLocation.substring(0, index3); } //check if the resourceLocation descriptor contains also remote repository information. ArtifactRepository repo = null; if (resourceLocation.startsWith("http://")) { final int repoDelimIntex = resourceLocation.indexOf('!'); String repoUrl = resourceLocation.substring(0, repoDelimIntex); repo = new DefaultArtifactRepository(repoUrl, repoUrl, new DefaultRepositoryLayout()); org.apache.maven.repository.Proxy mavenProxy = configureProxyToInlineRepo(); if (mavenProxy != null) { repo.setProxy(mavenProxy); } resourceLocation = resourceLocation.substring(repoDelimIntex + 1); } String[] parts = resourceLocation.split("/"); String groupId = parts[0]; String artifactId = parts[1]; String version = null; String classifier = null; String type = "jar"; if (parts.length > 2) { version = parts[2]; if (parts.length > 3) { type = parts[3]; if (parts.length > 4) { classifier = parts[4]; } } } else { Dependency dep = findDependency(project.getDependencies(), artifactId, groupId); if (dep == null && project.getDependencyManagement() != null) { dep = findDependency(project.getDependencyManagement().getDependencies(), artifactId, groupId); } if (dep != null) { version = dep.getVersion(); classifier = dep.getClassifier(); type = dep.getType(); } } if (version == null || version.length() == 0) { throw new MojoExecutionException("Cannot find version for: " + resourceLocation); } Artifact artifact = factory.createArtifactWithClassifier(groupId, artifactId, version, type, classifier); artifact.setRepository(repo); return artifact; }
From source file:com.webcohesion.enunciate.mojo.DeployArtifactBaseMojo.java
License:Apache License
private ArtifactRepository getDeploymentRepository() throws MojoExecutionException, MojoFailureException { if (deploymentRepository == null && altDeploymentRepository == null) { String msg = "Deployment failed: repository element was not specified in the pom inside" + " distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter"; throw new MojoExecutionException(msg); }//from ww w. ja v a 2 s . c o m ArtifactRepository repo = null; if (altDeploymentRepository != null) { getLog().info("Using alternate deployment repository " + altDeploymentRepository); Matcher matcher = ALT_REPO_SYNTAX_PATTERN.matcher(altDeploymentRepository); if (!matcher.matches()) { throw new MojoFailureException(altDeploymentRepository, "Invalid syntax for repository.", "Invalid syntax for alternative repository. Use \"id::layout::url\"."); } else { String id = matcher.group(1).trim(); String layout = matcher.group(2).trim(); String url = matcher.group(3).trim(); ArtifactRepositoryLayout repoLayout; try { repoLayout = (ArtifactRepositoryLayout) container.lookup(ArtifactRepositoryLayout.ROLE, layout); } catch (ComponentLookupException e) { throw new MojoExecutionException("Cannot find repository layout: " + layout, e); } repo = new DefaultArtifactRepository(id, url, repoLayout); } } if (repo == null) { repo = deploymentRepository; } return repo; }
From source file:hudson.maven.artifact.AbstractArtifactComponentTestCase.java
License:Apache License
protected ArtifactRepository localRepository() throws Exception { String path = "target/test-classes/repositories/" + component() + "/local-repository"; File f = new File(getBasedir(), path); ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup(ArtifactRepositoryLayout.ROLE, "default"); return new DefaultArtifactRepository("local", "file://" + f.getPath(), repoLayout); }
From source file:hudson.maven.artifact.AbstractArtifactComponentTestCase.java
License:Apache License
protected ArtifactRepository badRemoteRepository() throws Exception { ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup(ArtifactRepositoryLayout.ROLE, "default"); return new DefaultArtifactRepository("test", "http://foo.bar/repository", repoLayout); }
From source file:io.fabric8.maven.DeployToProfileMojo.java
License:Apache License
@SuppressWarnings("unchecked") protected void uploadDeploymentUnit(J4pClient client, boolean newUserAdded) throws Exception { String uri = getMavenUploadUri(client); // lets resolve the artifact to make sure we get a local file Artifact artifact = project.getArtifact(); ArtifactResolutionRequest request = new ArtifactResolutionRequest(); request.setArtifact(artifact);//from ww w . java 2 s . c o m addNeededRemoteRepository(); request.setRemoteRepositories(remoteRepositories); request.setLocalRepository(localRepository); resolver.resolve(request); String packaging = project.getPackaging(); File pomFile = project.getFile(); @SuppressWarnings("unchecked") List<Artifact> attachedArtifacts = project.getAttachedArtifacts(); DefaultRepositoryLayout layout = new DefaultRepositoryLayout(); ArtifactRepository repo = new DefaultArtifactRepository(serverId, uri, layout); if (newUserAdded) { // make sure to set authentication if we just added new user repo.setAuthentication(new Authentication(fabricServer.getUsername(), fabricServer.getPassword())); } // Deploy the POM boolean isPomArtifact = "pom".equals(packaging); if (!isPomArtifact) { ProjectArtifactMetadata metadata = new ProjectArtifactMetadata(artifact, pomFile); artifact.addMetadata(metadata); } try { if (isPomArtifact) { deploy(pomFile, artifact, repo, localRepository, retryFailedDeploymentCount); } else { File file = artifact.getFile(); // lets deploy the pom for the artifact first if (isFile(pomFile)) { deploy(pomFile, artifact, repo, localRepository, retryFailedDeploymentCount); } if (isFile(file)) { deploy(file, artifact, repo, localRepository, retryFailedDeploymentCount); } else if (!attachedArtifacts.isEmpty()) { getLog().info("No primary artifact to deploy, deploying attached artifacts instead."); Artifact pomArtifact = artifactFactory.createProjectArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getBaseVersion()); pomArtifact.setFile(pomFile); deploy(pomFile, pomArtifact, repo, localRepository, retryFailedDeploymentCount); // propagate the timestamped version to the main artifact for the attached artifacts to pick it up artifact.setResolvedVersion(pomArtifact.getVersion()); } else { String message = "The packaging for this project did not assign a file to the build artifact"; throw new MojoExecutionException(message); } } for (Artifact attached : attachedArtifacts) { deploy(attached.getFile(), attached, repo, localRepository, retryFailedDeploymentCount); } } catch (ArtifactDeploymentException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:net.sourceforge.vulcan.maven.integration.MavenIntegration.java
License:Open Source License
private ArtifactRepository createLocalRepository(Embedder embedder, Settings settings) throws ComponentLookupException { final ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout) embedder .lookup(ArtifactRepositoryLayout.ROLE, "default"); String url = settings.getLocalRepository(); if (!url.startsWith("file:")) { url = "file://" + url; }/*from w w w.j a va 2 s .co m*/ return new DefaultArtifactRepository("local", url, repositoryLayout); }
From source file:npanday.LocalRepositoryUtil.java
License:Apache License
public static ArtifactRepository create(URI uri) { return new DefaultArtifactRepository("local", uri.toString(), new DefaultRepositoryLayout()); }
From source file:org.apache.cactus.integration.maven2.test.CactifyMavenProjectStub.java
License:Apache License
/** * @return of remote artifact repositories */// w ww.java 2s.c o m public List getRemoteArtifactRepositories() { ArtifactRepository repository = new DefaultArtifactRepository("central", "file://" + PlexusTestCase.getBasedir() + "/src/test/remote-repo", new DefaultRepositoryLayout()); return Collections.singletonList(repository); }
From source file:org.apache.felix.karaf.tooling.features.ValidateFeaturesMojo.java
License:Apache License
private Artifact resolve(String bundle) throws Exception, ArtifactNotFoundException { Artifact artifact = getArtifact(bundle); if (bundle.indexOf(MVN_REPO_SEPARATOR) >= 0) { if (bundle.startsWith(MVN_URI_PREFIX)) { bundle = bundle.substring(MVN_URI_PREFIX.length()); }//from w ww . ja v a2 s .c o m String repo = bundle.substring(0, bundle.indexOf(MVN_REPO_SEPARATOR)); ArtifactRepository repository = new DefaultArtifactRepository(artifact.getArtifactId() + "-repo", repo, new DefaultRepositoryLayout()); List<ArtifactRepository> repos = new LinkedList<ArtifactRepository>(); repos.add(repository); resolver.resolve(artifact, repos, localRepo); } else { resolver.resolve(artifact, remoteRepos, localRepo); } if (artifact == null) { throw new Exception("Unable to resolve artifact for uri " + bundle); } else { return artifact; } }
From source file:org.apache.karaf.tooling.features.ValidateDescriptorMojo.java
License:Apache License
private Object resolve(String bundle) throws Exception, ArtifactNotFoundException { if (!isMavenProtocol(bundle)) { return bundle; }//from w w w. j a v a 2 s .c o m Artifact artifact = getArtifact(bundle); if (bundle.indexOf(MVN_REPO_SEPARATOR) >= 0) { if (bundle.startsWith(MVN_URI_PREFIX)) { bundle = bundle.substring(MVN_URI_PREFIX.length()); } String repo = bundle.substring(0, bundle.indexOf(MVN_REPO_SEPARATOR)); ArtifactRepository repository = new DefaultArtifactRepository(artifact.getArtifactId() + "-repo", repo, new DefaultRepositoryLayout()); List<ArtifactRepository> repos = new LinkedList<ArtifactRepository>(); repos.add(repository); resolver.resolve(artifact, repos, localRepo); } else { resolver.resolve(artifact, remoteRepos, localRepo); } if (artifact == null) { throw new Exception("Unable to resolve artifact for uri " + bundle); } else { return artifact; } }