use of org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout 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.layout.DefaultRepositoryLayout in project maven-plugins by apache.
the class JiraUnicodeTestProjectStub method getRemoteArtifactRepositories.
/** {@inheritDoc} */
@Override
public List<ArtifactRepository> getRemoteArtifactRepositories() {
ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy(true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE);
ArtifactRepository repository = new MavenArtifactRepository("central", "http://repo1.maven.org/maven2", new DefaultRepositoryLayout(), policy, policy);
return Collections.singletonList(repository);
}
use of org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout 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.layout.DefaultRepositoryLayout 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.layout.DefaultRepositoryLayout 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