use of org.jboss.modules.maven.ArtifactCoordinates in project wildfly-swarm by wildfly-swarm.
the class ApplicationModuleFinder method addDependencies.
protected void addDependencies(ModuleSpec.Builder builder, ApplicationEnvironment env) {
env.getDependencies().forEach((dep) -> {
String[] parts = dep.split(":");
ArtifactCoordinates coords = null;
if (!parts[2].equals("jar")) {
return;
}
if (parts.length == 4) {
coords = new ArtifactCoordinates(parts[0], parts[1], parts[3]);
} else if (parts.length == 5) {
coords = new ArtifactCoordinates(parts[0], parts[1], parts[4], parts[3]);
}
try {
File artifact = MavenResolvers.get().resolveJarArtifact(coords);
if (artifact == null) {
LOG.error("Unable to find artifact for " + coords);
return;
}
JarFile jar = JarFileManager.INSTANCE.addJarFile(artifact);
builder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(ResourceLoaders.createJarResourceLoader(artifact.getName(), jar)));
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}
use of org.jboss.modules.maven.ArtifactCoordinates in project jboss-modules by jboss-modules.
the class ModuleXmlParser method parseArtifact.
private static Version parseArtifact(final MavenResolver mavenResolver, final XmlPullParser reader, final ModuleSpec.Builder specBuilder) throws XmlPullParserException, IOException {
String name = null;
final Set<String> required = new HashSet<>(LIST_A_NAME);
final int count = reader.getAttributeCount();
for (int i = 0; i < count; i++) {
validateAttributeNamespace(reader, i);
final String attribute = reader.getAttributeName(i);
required.remove(attribute);
switch(attribute) {
case A_NAME:
name = reader.getAttributeValue(i);
break;
default:
throw unknownAttribute(reader, i);
}
}
if (!required.isEmpty()) {
throw missingAttributes(reader, required);
}
final MultiplePathFilterBuilder filterBuilder = PathFilters.multiplePathFilterBuilder(true);
final SystemPropertyConditionBuilder conditionBuilder = new SystemPropertyConditionBuilder();
final ResourceLoader resourceLoader;
final Set<String> encountered = new HashSet<>();
int eventType;
for (; ; ) {
eventType = reader.nextTag();
switch(eventType) {
case END_TAG:
{
if (conditionBuilder.resolve()) {
final ArtifactCoordinates coordinates;
try {
coordinates = ArtifactCoordinates.fromString(name);
resourceLoader = MavenArtifactUtil.createMavenArtifactLoader(mavenResolver, coordinates, name);
} catch (IOException | IllegalArgumentException e) {
throw new XmlPullParserException(String.format("Failed to add artifact '%s'", name), reader, e);
}
if (resourceLoader == null)
throw new XmlPullParserException(String.format("Failed to resolve artifact '%s'", name), reader, null);
specBuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(resourceLoader, filterBuilder.create()));
final String version = coordinates.getVersion();
try {
return Version.parse(version);
} catch (IllegalArgumentException ignored) {
return null;
}
}
return null;
}
case START_TAG:
{
validateNamespace(reader);
final String element = reader.getName();
if (!encountered.add(element))
throw unexpectedContent(reader);
switch(element) {
case E_FILTER:
parseFilterList(reader, filterBuilder);
break;
case E_CONDITIONS:
parseConditions(reader, conditionBuilder);
break;
default:
throw unexpectedContent(reader);
}
break;
}
default:
{
throw unexpectedContent(reader);
}
}
}
}
use of org.jboss.modules.maven.ArtifactCoordinates in project wildfly-swarm by wildfly-swarm.
the class ArtifactManager method findFile.
private File findFile(String gav) throws IOException, ModuleLoadException {
// groupId:artifactId
// groupId:artifactId:version
// groupId:artifactId:packaging:version
// groupId:artifactId:packaging:classifier:version
String[] parts = gav.split(COLON);
if (parts.length < 2) {
throw SwarmMessages.MESSAGES.gavMinimumSegments();
}
String groupId = parts[0];
String artifactId = parts[1];
String packaging = JAR;
String version = null;
String classifier = "";
if (parts.length == 3) {
version = parts[2];
}
if (parts.length == 4) {
// the type "test-jar" is packaged as a .jar file more info: https://maven.apache.org/plugins/maven-jar-plugin/examples/create-test-jar.html
packaging = TEST_JAR.equals(parts[2]) ? JAR : parts[2];
version = parts[3];
}
if (parts.length == 5) {
packaging = TEST_JAR.equals(parts[2]) ? JAR : parts[2];
classifier = parts[3];
version = parts[4];
}
if (version != null && (version.isEmpty() || version.equals("*"))) {
version = null;
}
if (version == null) {
version = determineVersionViaApplicationEnvironment(groupId, artifactId, packaging, classifier);
}
if (version == null) {
version = determineVersionViaClasspath(groupId, artifactId, packaging, classifier);
}
if (version == null) {
throw SwarmMessages.MESSAGES.unableToDetermineVersion(gav);
}
ArtifactCoordinates coords = new ArtifactCoordinates(groupId, artifactId, version, classifier == null ? "" : classifier);
return MavenResolvers.get().resolveArtifact(coords, packaging);
}
use of org.jboss.modules.maven.ArtifactCoordinates in project wildfly-swarm by wildfly-swarm.
the class GradleResolverTest method testToGradleArtifactFileName_withClassifier.
@Test
public void testToGradleArtifactFileName_withClassifier() {
// GIVEN
String group = "org.wildfly.swarm";
String packaging = "jar";
String artifact = "test";
String version = "1.0";
String classifier = "sources";
ArtifactCoordinates artifactCoordinates = new ArtifactCoordinates(group, artifact, version, classifier);
// WHEN
GradleResolver resolver = new GradleResolver(null);
String artifactFileName = resolver.toGradleArtifactFileName(artifactCoordinates, packaging);
// THEN
assertEquals(artifact + "-" + version + "-" + classifier + "." + packaging, artifactFileName);
}
use of org.jboss.modules.maven.ArtifactCoordinates in project wildfly-swarm by wildfly-swarm.
the class GradleResolverTest method downloadFromRemoteRepository_unknown.
@Test
public void downloadFromRemoteRepository_unknown() throws IOException {
// GIVEN
File dirFile = TempFileManager.INSTANCE.newTempDirectory(".gradle", null);
Path gradleCachePath = dirFile.toPath();
String group = "org.wildfly.swarm";
String packaging = "jar";
String artifact = "test";
String version = "2017.1.1";
ArtifactCoordinates artifactCoordinates = new ArtifactCoordinates(group, artifact, version);
Path artifactDirectory = gradleCachePath.resolve(group);
GradleResolver resolver = spy(new GradleResolver(gradleCachePath.toString()));
doReturn(null).when(resolver).doDownload(anyString(), anyString(), anyString(), eq(artifactCoordinates), eq(packaging), any(File.class), any(File.class));
// WHEN
File result = resolver.downloadFromRemoteRepository(artifactCoordinates, packaging, artifactDirectory);
// THEN
assertNull(result);
}
Aggregations