List of usage examples for org.apache.maven.artifact Artifact setRepository
void setRepository(ArtifactRepository remoteRepository);
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 ww w.j av a 2 s.co 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:org.apache.karaf.tooling.utils.MojoSupport.java
License:Apache License
/** * Convert a feature resourceLocation (bundle or configuration file) into an artifact. * * @param resourceLocation the feature resource location (bundle or configuration file). * @param skipNonMavenProtocols flag to skip protocol different than mvn: * @return the artifact corresponding to the resource. * @throws MojoExecutionException//from w ww.ja v a2s . c o m */ protected Artifact resourceToArtifact(String resourceLocation, boolean skipNonMavenProtocols) throws MojoExecutionException { resourceLocation = resourceLocation.replace("\r\n", "").replace("\n", "").replace(" ", "").replace("\t", ""); 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.isEmpty()) { 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:org.codehaus.mojo.repositorytools.discoverer.WagonDiscoverer.java
/** * Returns an artifact object that is represented by the specified path in a * repository//from w w w.jav a 2s.c om * * @param path * The path that is pointing to an artifact * @param repository * The repository of the artifact * @return Artifact * @throws DiscovererException * when the specified path does correspond to an artifact */ public Artifact buildArtifactFromPath(String path, ArtifactRepository repository) throws DiscovererException { Artifact artifact = buildArtifact(path); if (artifact != null) { artifact.setRepository(repository); artifact.setFile(new File(repository.getBasedir(), path)); } return artifact; }
From source file:org.opennms.maven.plugins.karaf.utils.MojoSupport.java
License:Apache License
/** * Convert a feature resourceLocation (bundle or configuration file) into an artifact. * * @param resourceLocation the feature resource location (bundle or configuration file). * @param skipNonMavenProtocols flag to skip protocol different than mvn: * @return the artifact corresponding to the resource. * @throws MojoExecutionException//from w w w.j a v a 2 s . c om */ protected Artifact resourceToArtifact(String resourceLocation, boolean skipNonMavenProtocols) throws MojoExecutionException { resourceLocation = resourceLocation.replace("\r\n", "").replace("\n", "").replace(" ", "").replace("\t", ""); 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 repoDelimIndex = resourceLocation.indexOf('!'); String repoUrl = resourceLocation.substring(0, repoDelimIndex); int paramIndex = repoUrl.indexOf("@"); if (paramIndex >= 0) { repoUrl = repoUrl.substring(0, paramIndex); } repo = new DefaultArtifactRepository(repoUrl, repoUrl, new DefaultRepositoryLayout()); org.apache.maven.repository.Proxy mavenProxy = configureProxyToInlineRepo(); if (mavenProxy != null) { repo.setProxy(mavenProxy); } resourceLocation = resourceLocation.substring(repoDelimIndex + 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.isEmpty()) { throw new MojoExecutionException("Cannot find version for: " + resourceLocation); } Artifact artifact = factory.createArtifactWithClassifier(groupId, artifactId, version, type, classifier); artifact.setRepository(repo); return artifact; }