use of org.apache.maven.artifact.versioning.InvalidVersionSpecificationException in project camel by apache.
the class RunMojo method getAllDependencies.
// generic method to retrieve all the transitive dependencies
private Collection<Artifact> getAllDependencies() throws MojoExecutionException {
List<Artifact> artifacts = new ArrayList<Artifact>();
for (Iterator<?> dependencies = project.getDependencies().iterator(); dependencies.hasNext(); ) {
Dependency dependency = (Dependency) dependencies.next();
String groupId = dependency.getGroupId();
String artifactId = dependency.getArtifactId();
VersionRange versionRange;
try {
versionRange = VersionRange.createFromVersionSpec(dependency.getVersion());
} catch (InvalidVersionSpecificationException e) {
throw new MojoExecutionException("unable to parse version", e);
}
String type = dependency.getType();
if (type == null) {
type = "jar";
}
String classifier = dependency.getClassifier();
boolean optional = dependency.isOptional();
String scope = dependency.getScope();
if (scope == null) {
scope = Artifact.SCOPE_COMPILE;
}
Artifact art = this.artifactFactory.createDependencyArtifact(groupId, artifactId, versionRange, type, classifier, scope, null, optional);
if (scope.equalsIgnoreCase(Artifact.SCOPE_SYSTEM)) {
art.setFile(new File(dependency.getSystemPath()));
}
List<String> exclusions = new ArrayList<String>();
for (Exclusion exclusion : dependency.getExclusions()) {
exclusions.add(exclusion.getGroupId() + ":" + exclusion.getArtifactId());
}
ArtifactFilter newFilter = new ExcludesArtifactFilter(exclusions);
art.setDependencyFilter(newFilter);
artifacts.add(art);
}
return artifacts;
}
use of org.apache.maven.artifact.versioning.InvalidVersionSpecificationException in project aries by apache.
the class EsaMavenProjectStub9 method getArtifacts.
public Set getArtifacts() {
try {
Set artifacts = new HashSet();
artifacts.add(createArtifact("org.apache.maven.test", "maven-artifact01", "1.0-SNAPSHOT", false));
Artifact artifact02 = createArtifact("org.apache.maven.test", "maven-artifact02", "1.0-SNAPSHOT", false);
artifact02.setVersionRange(VersionRange.createFromVersionSpec("[1.3, 2.5)"));
artifacts.add(artifact02);
artifacts.add(createArtifact("org.apache.maven.test", "maven-artifact03", "1.1-SNAPSHOT", false));
artifacts.add(createArtifact("org.apache.maven.test", "maven-artifact04", "1.2-SNAPSHOT", "esa", true));
return artifacts;
} catch (InvalidVersionSpecificationException e) {
throw new RuntimeException(e);
}
}
use of org.apache.maven.artifact.versioning.InvalidVersionSpecificationException in project karaf by apache.
the class MojoSupport method createManagedVersionMap.
protected Map createManagedVersionMap(String projectId, DependencyManagement dependencyManagement) throws ProjectBuildingException {
Map map;
if (dependencyManagement != null && dependencyManagement.getDependencies() != null) {
map = new HashMap();
for (Dependency d : dependencyManagement.getDependencies()) {
try {
VersionRange versionRange = VersionRange.createFromVersionSpec(d.getVersion());
Artifact artifact = factory.createDependencyArtifact(d.getGroupId(), d.getArtifactId(), versionRange, d.getType(), d.getClassifier(), d.getScope());
map.put(d.getManagementKey(), artifact);
} catch (InvalidVersionSpecificationException e) {
throw new ProjectBuildingException(projectId, "Unable to parse version '" + d.getVersion() + "' for dependency '" + d.getManagementKey() + "': " + e.getMessage(), e);
}
}
} else {
map = Collections.EMPTY_MAP;
}
return map;
}
use of org.apache.maven.artifact.versioning.InvalidVersionSpecificationException in project camel by apache.
the class RunMojo method getAllDependencies.
// generic method to retrieve all the transitive dependencies
private Collection<Artifact> getAllDependencies() throws MojoExecutionException {
List<Artifact> artifacts = new ArrayList<Artifact>();
for (Iterator<?> dependencies = project.getDependencies().iterator(); dependencies.hasNext(); ) {
Dependency dependency = (Dependency) dependencies.next();
String groupId = dependency.getGroupId();
String artifactId = dependency.getArtifactId();
VersionRange versionRange;
try {
versionRange = VersionRange.createFromVersionSpec(dependency.getVersion());
} catch (InvalidVersionSpecificationException e) {
throw new MojoExecutionException("unable to parse version", e);
}
String type = dependency.getType();
if (type == null) {
type = "jar";
}
String classifier = dependency.getClassifier();
boolean optional = dependency.isOptional();
String scope = dependency.getScope();
if (scope == null) {
scope = Artifact.SCOPE_COMPILE;
}
Artifact art = this.artifactFactory.createDependencyArtifact(groupId, artifactId, versionRange, type, classifier, scope, null, optional);
if (scope.equalsIgnoreCase(Artifact.SCOPE_SYSTEM)) {
art.setFile(new File(dependency.getSystemPath()));
}
List<String> exclusions = new ArrayList<String>();
for (Exclusion exclusion : dependency.getExclusions()) {
exclusions.add(exclusion.getGroupId() + ":" + exclusion.getArtifactId());
}
ArtifactFilter newFilter = new ExcludesArtifactFilter(exclusions);
art.setDependencyFilter(newFilter);
artifacts.add(art);
}
return artifacts;
}
use of org.apache.maven.artifact.versioning.InvalidVersionSpecificationException in project midpoint by Evolveum.
the class SchemaDistMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("SchemaDist plugin started");
try {
processArtifactItems();
} catch (InvalidVersionSpecificationException e) {
handleFailure(e);
}
final File outDir = initializeOutDir(outputDirectory);
CatalogManager catalogManager = new CatalogManager();
catalogManager.setVerbosity(999);
for (ArtifactItem artifactItem : artifactItems) {
Artifact artifact = artifactItem.getArtifact();
getLog().info("SchemaDist unpacking artifact " + artifact);
File workDir = new File(workDirectory, artifact.getArtifactId());
initializeOutDir(workDir);
artifactItem.setWorkDir(workDir);
unpack(artifactItem, workDir);
if (translateSchemaLocation) {
String catalogPath = artifactItem.getCatalog();
if (catalogPath != null) {
File catalogFile = new File(workDir, catalogPath);
if (!catalogFile.exists()) {
throw new MojoExecutionException("No catalog file " + catalogPath + " in artifact " + artifact);
}
Catalog catalog = new Catalog(catalogManager);
catalog.setupReaders();
try {
// UGLY HACK. On Windows, file names like d:\abc\def\catalog.xml eventually get treated very strangely
// (resulting in names like "file:<current-working-dir>d:\abc\def\catalog.xml" that are obviously wrong)
// Prefixing such names with "file:/" helps.
String prefix;
if (catalogFile.isAbsolute() && !catalogFile.getPath().startsWith("/")) {
prefix = "/";
} else {
prefix = "";
}
String fileName = "file:" + prefix + catalogFile.getPath();
getLog().debug("Calling parseCatalog with: " + fileName);
catalog.parseCatalog(fileName);
} catch (MalformedURLException e) {
throw new MojoExecutionException("Error parsing catalog file " + catalogPath + " in artifact " + artifact, e);
} catch (IOException e) {
throw new MojoExecutionException("Error parsing catalog file " + catalogPath + " in artifact " + artifact, e);
}
artifactItem.setResolveCatalog(catalog);
}
} else {
getLog().debug("Catalog search disabled for " + artifact);
}
}
for (ArtifactItem artifactItem : artifactItems) {
Artifact artifact = artifactItem.getArtifact();
getLog().info("SchemaDist processing artifact " + artifact);
final File workDir = artifactItem.getWorkDir();
FileVisitor<Path> fileVisitor = new FileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
// nothing to do
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path filePath, BasicFileAttributes attrs) throws IOException {
String fileName = filePath.getFileName().toString();
if (fileName.endsWith(".xsd")) {
getLog().debug("=======================> Processing file " + filePath);
try {
processXsd(filePath, workDir, outDir);
} catch (MojoExecutionException | MojoFailureException e) {
throw new RuntimeException(e.getMessage(), e);
}
} else if (fileName.endsWith(".wsdl")) {
getLog().debug("=======================> Processing file " + filePath);
try {
processWsdl(filePath, workDir, outDir);
} catch (MojoExecutionException | MojoFailureException e) {
throw new RuntimeException(e.getMessage(), e);
}
} else {
getLog().debug("=======================> Skipping file " + filePath);
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
return FileVisitResult.TERMINATE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
// nothing to do
return FileVisitResult.CONTINUE;
}
};
try {
Files.walkFileTree(workDir.toPath(), fileVisitor);
} catch (IOException e) {
throw new MojoExecutionException("Error processing files of artifact " + artifact, e);
}
}
getLog().info("SchemaDist plugin finished");
}
Aggregations