Skip to content

Commit ad3b498

Browse files
authored
Merge pull request #64 from egineering-llc/feature/id-only-resolution
Implement Id-only repository resolution.
2 parents 20e355e + 5012105 commit ad3b498

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/main/java/com/e_gineering/maven/gitflowhelper/AbstractGitflowBasedRepositoryMojo.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.apache.maven.artifact.repository.ArtifactRepository;
44
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
55
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
6+
import org.apache.maven.model.Repository;
67
import org.apache.maven.plugin.MojoExecutionException;
78
import org.apache.maven.plugin.MojoFailureException;
89
import org.apache.maven.plugins.annotations.Component;
@@ -87,23 +88,38 @@ public abstract class AbstractGitflowBasedRepositoryMojo extends AbstractGitflow
8788
*/
8889
protected ArtifactRepository getDeploymentRepository(final String altRepository) throws MojoExecutionException, MojoFailureException {
8990
Matcher matcher = ALT_REPO_SYNTAX_PATTERN.matcher(altRepository);
91+
Repository candidate = null;
9092
if (!matcher.matches()) {
91-
throw new MojoFailureException(altRepository, "Invalid syntax for repository.",
92-
"Invalid syntax for repository. Use \"id::layout::url::unique\".");
93+
for (int i = 0; i < project.getRepositories().size(); i++) {
94+
candidate = project.getRepositories().get(i);
95+
if (candidate.getId().equals(altRepository)) {
96+
break;
97+
}
98+
candidate = null;
99+
}
100+
101+
if (candidate == null) {
102+
throw new MojoFailureException(altRepository, "Invalid syntax for repository or repository id not resolved..",
103+
"Invalid syntax for repository. Use \"id::layout::url::unique\" or only specify the \"id\".");
104+
}
93105
}
94106

95107
if (getLog().isDebugEnabled()) {
96108
getLog().debug("Getting maven deployment repository (to target artifacts) for: " + altRepository);
97109
}
98110

99-
String id = matcher.group(1).trim();
100-
String layout = matcher.group(2).trim();
101-
String url = matcher.group(3).trim();
102-
boolean unique = Boolean.parseBoolean(matcher.group(4).trim());
111+
if (candidate == null) {
112+
String id = matcher.group(1).trim();
113+
String layout = matcher.group(2).trim();
114+
String url = matcher.group(3).trim();
115+
boolean unique = Boolean.parseBoolean(matcher.group(4).trim());
103116

104-
ArtifactRepositoryLayout repoLayout = getLayout(layout);
117+
ArtifactRepositoryLayout repoLayout = getLayout(layout);
105118

106-
return repositoryFactory.createDeploymentArtifactRepository(id, url, repoLayout, unique);
119+
return repositoryFactory.createDeploymentArtifactRepository(id, url, repoLayout, unique);
120+
} else {
121+
return repositoryFactory.createDeploymentArtifactRepository(candidate.getId(), candidate.getUrl(), getLayout(candidate.getLayout()), candidate.getSnapshots().isEnabled());
122+
}
107123
}
108124

109125
/**

0 commit comments

Comments
 (0)