use of org.apache.maven.artifact.repository.DefaultArtifactRepository in project intellij-community by JetBrains.
the class Maven2ServerIndexFetcher method connect.
public void connect(String _ignoredContextId, String _ignoredUrl) throws IOException {
final ArtifactRepository mirrorRepository = myWagonManager.getMirrorRepository(new DefaultArtifactRepository(myOriginalRepositoryId, myOriginalRepositoryUrl, null));
String mirrorUrl = mirrorRepository.getUrl();
String indexUrl = mirrorUrl + (mirrorUrl.endsWith("/") ? "" : "/") + ".index";
Repository repository = new Repository(myOriginalRepositoryId, indexUrl);
try {
myWagon = myWagonManager.getWagon(repository);
myWagon.addTransferListener(myListener);
myWagon.connect(repository, myWagonManager.getAuthenticationInfo(mirrorRepository.getId()), myWagonManager.getProxy(mirrorRepository.getProtocol()));
} catch (AuthenticationException e) {
IOException newEx = new IOException("Authentication exception connecting to " + repository);
newEx.initCause(e);
throw newEx;
} catch (WagonException e) {
IOException newEx = new IOException("Wagon exception connecting to " + repository);
newEx.initCause(e);
throw newEx;
}
}
use of org.apache.maven.artifact.repository.DefaultArtifactRepository in project karaf by apache.
the class MojoSupport method resourceToArtifact.
/**
* Convert a feature resourceLocation (bundle or configuration file) into an artifact.
*
* @param resourceLocation The feature resource location (bundle or configuration file).
* @param skipNonMavenProtocols A flag to skip protocol different than mvn:
* @return The artifact corresponding to the resource.
* @throws MojoExecutionException If the plugin execution fails.
*/
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;
}
use of org.apache.maven.artifact.repository.DefaultArtifactRepository in project maven-plugins by apache.
the class BundlePackMojoTest method testPack_RemoveTwo.
public void testPack_RemoveTwo() throws Exception {
File testPom = new File(getBasedir(), "src/test/resources/unit/bundle-pack/pom.xml");
BundlePackMojo mojo = (BundlePackMojo) lookupMojo("bundle-pack", testPom);
URL repoURL = new File(getBasedir(), "src/test/resources/repo").toURL();
mojo.localRepository = new DefaultArtifactRepository("test", repoURL.toString(), new DefaultRepositoryLayout());
// NOTE: This is sensitive to the lookupMojo method timing...
TestInputHandler ih = (TestInputHandler) lookup(InputHandler.ROLE, "default");
Stack<String> responses = new Stack<String>();
responses.push("2,3");
ih.setLineResponses(responses);
File generatedFilesDir = new File(getBasedir(), "target/bundle-pack-tests");
mojo.basedir = generatedFilesDir.getAbsolutePath();
mojo.execute();
File bundleSource = new File(generatedFilesDir, "testartifact-1.0-bundle.jar");
Set<String> entryNames = new HashSet<String>();
entryNames.add("testartifact-1.0.jar");
entryNames.add("pom.xml");
entryNames.add("META-INF/MANIFEST.MF");
entryNames.add("META-INF/");
Set<String> bannedNames = new HashSet<String>();
// determined experimentally, so this could change!
bannedNames.add("testartifact-1.0-sources.jar");
bannedNames.add("testartifact-1.0-javadoc.jar");
assertZipContents(entryNames, bannedNames, bundleSource);
}
use of org.apache.maven.artifact.repository.DefaultArtifactRepository in project maven-plugins by apache.
the class BundlePackMojoTest method testPack.
public void testPack() throws Exception {
File testPom = new File(getBasedir(), "src/test/resources/unit/bundle-pack/pom.xml");
BundlePackMojo mojo = (BundlePackMojo) lookupMojo("bundle-pack", testPom);
URL repoURL = new File(getBasedir(), "src/test/resources/repo").toURL();
mojo.localRepository = new DefaultArtifactRepository("test", repoURL.toString(), new DefaultRepositoryLayout());
File generatedFilesDir = new File(getBasedir(), "target/bundle-pack-tests");
mojo.basedir = generatedFilesDir.getAbsolutePath();
mojo.execute();
File bundleSource = new File(generatedFilesDir, "testartifact-1.0-bundle.jar");
Set<String> entryNames = new HashSet<String>();
entryNames.add("testartifact-1.0-javadoc.jar");
entryNames.add("testartifact-1.0-sources.jar");
entryNames.add("testartifact-1.0.jar");
entryNames.add("pom.xml");
entryNames.add("META-INF/MANIFEST.MF");
entryNames.add("META-INF/");
assertZipContents(entryNames, Assertions.EMPTY_ENTRY_NAMES, bundleSource);
}
use of org.apache.maven.artifact.repository.DefaultArtifactRepository in project maven-plugins by apache.
the class BundlePackMojoTest method testPack_RemoveTwoUnordered.
public void testPack_RemoveTwoUnordered() throws Exception {
File testPom = new File(getBasedir(), "src/test/resources/unit/bundle-pack/pom.xml");
BundlePackMojo mojo = (BundlePackMojo) lookupMojo("bundle-pack", testPom);
URL repoURL = new File(getBasedir(), "src/test/resources/repo").toURL();
mojo.localRepository = new DefaultArtifactRepository("test", repoURL.toString(), new DefaultRepositoryLayout());
// NOTE: This is sensitive to the lookupMojo method timing...
TestInputHandler ih = (TestInputHandler) lookup(InputHandler.ROLE, "default");
Stack<String> responses = new Stack<String>();
responses.push("3,2");
ih.setLineResponses(responses);
File generatedFilesDir = new File(getBasedir(), "target/bundle-pack-tests");
mojo.basedir = generatedFilesDir.getAbsolutePath();
mojo.execute();
File bundleSource = new File(generatedFilesDir, "testartifact-1.0-bundle.jar");
Set<String> entryNames = new HashSet<String>();
entryNames.add("testartifact-1.0.jar");
entryNames.add("pom.xml");
entryNames.add("META-INF/MANIFEST.MF");
entryNames.add("META-INF/");
Set<String> bannedNames = new HashSet<String>();
// determined experimentally, so this could change!
bannedNames.add("testartifact-1.0-sources.jar");
bannedNames.add("testartifact-1.0-javadoc.jar");
assertZipContents(entryNames, bannedNames, bundleSource);
}
Aggregations