Search in sources :

Example 1 with InvalidVersionSpecificationException

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;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) VersionRange(org.apache.maven.artifact.versioning.VersionRange) Dependency(org.apache.maven.model.Dependency) ExecutableDependency(org.codehaus.mojo.exec.ExecutableDependency) Artifact(org.apache.maven.artifact.Artifact) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ExcludesArtifactFilter(org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) ExcludesArtifactFilter(org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter) Exclusion(org.apache.maven.model.Exclusion) File(java.io.File)

Example 2 with InvalidVersionSpecificationException

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);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) Artifact(org.apache.maven.artifact.Artifact) HashSet(java.util.HashSet)

Example 3 with InvalidVersionSpecificationException

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;
}
Also used : ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) HashMap(java.util.HashMap) VersionRange(org.apache.maven.artifact.versioning.VersionRange) Dependency(org.apache.maven.model.Dependency) HashMap(java.util.HashMap) Map(java.util.Map) Artifact(org.apache.maven.artifact.Artifact)

Example 4 with InvalidVersionSpecificationException

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;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) VersionRange(org.apache.maven.artifact.versioning.VersionRange) Dependency(org.apache.maven.model.Dependency) ExecutableDependency(org.codehaus.mojo.exec.ExecutableDependency) Artifact(org.apache.maven.artifact.Artifact) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ExcludesArtifactFilter(org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) ExcludesArtifactFilter(org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter) Exclusion(org.apache.maven.model.Exclusion) File(java.io.File)

Example 5 with InvalidVersionSpecificationException

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");
}
Also used : Path(java.nio.file.Path) MalformedURLException(java.net.MalformedURLException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) CatalogManager(org.apache.xml.resolver.CatalogManager) Artifact(org.apache.maven.artifact.Artifact) Catalog(org.apache.xml.resolver.Catalog) InvalidVersionSpecificationException(org.apache.maven.artifact.versioning.InvalidVersionSpecificationException) FileVisitor(java.nio.file.FileVisitor) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Aggregations

Artifact (org.apache.maven.artifact.Artifact)7 InvalidVersionSpecificationException (org.apache.maven.artifact.versioning.InvalidVersionSpecificationException)7 VersionRange (org.apache.maven.artifact.versioning.VersionRange)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 Dependency (org.apache.maven.model.Dependency)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ArtifactMetadataRetrievalException (org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException)2 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)2 ExcludesArtifactFilter (org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter)2 ArtifactVersion (org.apache.maven.artifact.versioning.ArtifactVersion)2 Exclusion (org.apache.maven.model.Exclusion)2 ProjectBuildingException (org.apache.maven.project.ProjectBuildingException)2 ExecutableDependency (org.codehaus.mojo.exec.ExecutableDependency)2 MalformedURLException (java.net.MalformedURLException)1 FileVisitor (java.nio.file.FileVisitor)1 Path (java.nio.file.Path)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1