Skip to content

Commit

Permalink
Merge branch 'master' into ramon-master
Browse files Browse the repository at this point in the history
* master:
  #186 - Change artifactId to "dkpro-core-XXX"
  • Loading branch information
reckart committed Jun 1, 2019
2 parents 6b7a344 + 70cfbb5 commit b9e4920
Showing 1 changed file with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public abstract class ResourceObjectProviderBase<M>
* resolved when {@link #configure()} is called. (optional)
*/
public static final String GROUP_ID = "groupId";
public static final String COMPONENT_GROUP_ID = "componentGroupId";

/**
* The artifact ID of the Maven artifact containing a resource. Variables in the location are
Expand Down Expand Up @@ -212,6 +213,7 @@ public abstract class ResourceObjectProviderBase<M>
protected void init()
{
setDefault(GROUP_ID, "de.tudarmstadt.ukp.dkpro.core");
setDefault(COMPONENT_GROUP_ID, "org.dkpro.core");
setDefault(ARTIFACT_URI,
"mvn:${" + GROUP_ID + "}:${" + ARTIFACT_ID + "}:${" + VERSION + "}");
}
Expand Down Expand Up @@ -374,7 +376,7 @@ public void applyAutoOverrides(Object aObject)
}
}

protected List<URL> getPomUrlsForClass(String aModelGroup, String aModelArtifact,
protected List<URL> getPomUrlsForClass(String aComponentGroupId, String aModelArtifactId,
Class<?> aClass)
throws IOException
{
Expand Down Expand Up @@ -418,7 +420,7 @@ protected List<URL> getPomUrlsForClass(String aModelGroup, String aModelArtifact
Matcher matcher = pattern.matcher(base);
if (matcher.matches()) {
String artifactIdAndVersion = matcher.group("ID");
String pomPattern = base + "META-INF/maven/" + aModelGroup + "/"
String pomPattern = base + "META-INF/maven/" + aComponentGroupId + "/"
+ artifactIdAndVersion + "/pom.xml";
lookupPatterns.add(pomPattern);
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Expand All @@ -434,9 +436,9 @@ protected List<URL> getPomUrlsForClass(String aModelGroup, String aModelArtifact
// models from the StanfordNLP module).
if (urls.isEmpty()) {
// This is the default strategy supposed to look in the JAR
String moduleArtifactId = aModelArtifact.split("-")[0];
String pomPattern = base + "META-INF/maven/" + aModelGroup + "/" + moduleArtifactId +
"*/pom.xml";
String moduleArtifactId = aModelArtifactId.split("-")[0];
String pomPattern = base + "META-INF/maven/" + aComponentGroupId + "/"
+ moduleArtifactId + "*/pom.xml";
lookupPatterns.add(pomPattern);
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources(pomPattern);
Expand Down Expand Up @@ -468,11 +470,11 @@ protected List<URL> getPomUrlsForClass(String aModelGroup, String aModelArtifact
* the POM, or if no context object was set.
* @return the version of the required model.
*/
protected String getModelVersionFromMavenPom(String aModelGroup, String aModelArtifact,
Class<?> aClass)
protected String getModelVersionFromMavenPom(String aComponentGroupId, String aModelGroupId,
String aModelArtifactId, Class<?> aClass)
throws IOException
{
List<URL> urls = getPomUrlsForClass(aModelGroup, aModelArtifact, contextClass);
List<URL> urls = getPomUrlsForClass(aComponentGroupId, aModelArtifactId, contextClass);

for (URL pomUrl : urls) {
// Parse the POM
Expand All @@ -492,8 +494,8 @@ protected String getModelVersionFromMavenPom(String aModelGroup, String aModelAr
List<Dependency> deps = model.getDependencyManagement().getDependencies();
for (Dependency dep : deps) {
if (
StringUtils.equals(dep.getGroupId(), aModelGroup) &&
StringUtils.equals(dep.getArtifactId(), aModelArtifact)
StringUtils.equals(dep.getGroupId(), aModelGroupId) &&
StringUtils.equals(dep.getArtifactId(), aModelArtifactId)
) {
return dep.getVersion();
}
Expand Down Expand Up @@ -790,12 +792,22 @@ private Properties resolveDependency(Properties aProps)
resolved.getProperty(ARTIFACT_URI, "").contains("${" + VERSION + "}") &&
isNull(resolved.getProperty(VERSION))
) {
String groupId = pph.replacePlaceholders(aProps.getProperty(GROUP_ID), resolved);
String modelGroupId = pph.replacePlaceholders(aProps.getProperty(GROUP_ID), resolved);
String componentGroupId;

if (aProps.getProperty(COMPONENT_GROUP_ID) != null) {
componentGroupId = pph.replacePlaceholders(aProps.getProperty(COMPONENT_GROUP_ID),
resolved);
}
else {
componentGroupId = modelGroupId;
}

String artifactId = pph.replacePlaceholders(aProps.getProperty(ARTIFACT_ID), resolved);
try {
// If the version is to be auto-detected, then we must have a groupId and artifactId
resolved.put(VERSION,
getModelVersionFromMavenPom(groupId, artifactId, contextClass));
resolved.put(VERSION, getModelVersionFromMavenPom(componentGroupId, modelGroupId,
artifactId, contextClass));
}
catch (Throwable e) {
log.error("Unable to obtain version from POM", e);
Expand Down

0 comments on commit b9e4920

Please sign in to comment.