Search in sources :

Example 41 with MojoExecutionException

use of org.apache.maven.plugin.MojoExecutionException in project karaf by apache.

the class Dependency31Helper method getDependencyTree.

private DependencyNode getDependencyTree(Artifact artifact) throws MojoExecutionException {
    try {
        CollectRequest collectRequest = new CollectRequest(new Dependency(artifact, "compile"), null, projectRepositories);
        DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySystemSession);
        session.setDependencySelector(new AndDependencySelector(new OptionalDependencySelector(), new ScopeDependencySelector1(), new ExclusionDependencySelector()));
        // between aether-util 0.9.0.M1 and M2, JavaEffectiveScopeCalculator was removed
        // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=397241
        DependencyGraphTransformer transformer = new ChainedDependencyGraphTransformer(new ConflictMarker(), new ConflictResolver(new NearestVersionSelector(), new JavaScopeSelector(), new SimpleOptionalitySelector(), new JavaScopeDeriver()), new JavaDependencyContextRefiner());
        session.setDependencyGraphTransformer(transformer);
        CollectResult result = repositorySystem.collectDependencies(session, collectRequest);
        return result.getRoot();
    } catch (DependencyCollectionException e) {
        throw new MojoExecutionException("Cannot build project dependency tree", e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AndDependencySelector(org.eclipse.aether.util.graph.selector.AndDependencySelector) Dependency(org.eclipse.aether.graph.Dependency) OptionalDependencySelector(org.eclipse.aether.util.graph.selector.OptionalDependencySelector) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) ExclusionDependencySelector(org.eclipse.aether.util.graph.selector.ExclusionDependencySelector)

Example 42 with MojoExecutionException

use of org.apache.maven.plugin.MojoExecutionException in project karaf by apache.

the class AbstractFeatureMojo method resolveFeatures.

protected Set<Feature> resolveFeatures() throws MojoExecutionException {
    Set<Feature> featuresSet = new HashSet<>();
    try {
        Set<String> artifactsToCopy = new HashSet<>();
        Map<String, Feature> featuresMap = new HashMap<>();
        for (String uri : descriptors) {
            retrieveDescriptorsRecursively(uri, artifactsToCopy, featuresMap);
        }
        // no features specified, handle all of them
        if (features == null) {
            features = new ArrayList<>(featuresMap.keySet());
        }
        addFeatures(features, featuresSet, featuresMap, addTransitiveFeatures);
        getLog().info("Using local repository at: " + localRepo.getUrl());
        for (Feature feature : featuresSet) {
            try {
                for (Bundle bundle : feature.getBundle()) {
                    resolveArtifact(bundle.getLocation());
                }
                for (Conditional conditional : feature.getConditional()) {
                    for (BundleInfo bundle : conditional.getBundles()) {
                        if (ignoreDependencyFlag || (!ignoreDependencyFlag && !bundle.isDependency())) {
                            resolveArtifact(bundle.getLocation());
                        }
                    }
                }
                for (ConfigFile configfile : feature.getConfigfile()) {
                    resolveArtifact(configfile.getLocation());
                }
            } catch (RuntimeException e) {
                throw new RuntimeException("Error resolving feature " + feature.getName() + "/" + feature.getVersion(), e);
            }
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Error populating repository", e);
    }
    return featuresSet;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) ConfigFile(org.apache.karaf.features.internal.model.ConfigFile) Bundle(org.apache.karaf.features.internal.model.Bundle) Conditional(org.apache.karaf.features.Conditional) Feature(org.apache.karaf.features.internal.model.Feature) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) BundleInfo(org.apache.karaf.features.BundleInfo) HashSet(java.util.HashSet)

Example 43 with MojoExecutionException

use of org.apache.maven.plugin.MojoExecutionException in project karaf by apache.

the class ExportFeatureMetaDataMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    Set<Feature> featuresSet = resolveFeatures();
    if (mergedFeature) {
        Feature feature = oneVersion ? mergeFeatureOneVersion(featuresSet) : mergeFeature(featuresSet);
        featuresSet = new HashSet<>();
        featuresSet.add(feature);
    }
    try {
        metaDataFile.getParentFile().mkdirs();
        Features features = new Features();
        features.getFeature().addAll(featuresSet);
        try (OutputStream os = new FileOutputStream(metaDataFile)) {
            JaxbUtil.marshal(features, os);
        }
    } catch (Exception e) {
        throw new RuntimeException("Error writing feature meta data to " + metaDataFile + ": " + e.getMessage(), e);
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Features(org.apache.karaf.features.internal.model.Features) Feature(org.apache.karaf.features.internal.model.Feature) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 44 with MojoExecutionException

use of org.apache.maven.plugin.MojoExecutionException in project karaf by apache.

the class AbstractFeatureMojo method addFeatureRepo.

protected void addFeatureRepo(String featureUrl) throws MojoExecutionException {
    Artifact featureDescArtifact = resourceToArtifact(featureUrl, true);
    if (featureDescArtifact == null) {
        return;
    }
    try {
        resolveArtifact(featureDescArtifact, remoteRepos);
        descriptors.add(0, featureUrl);
    } catch (Exception e) {
        getLog().warn("Can't add " + featureUrl + " in the descriptors set");
        getLog().debug(e);
    }
}
Also used : Artifact(org.apache.maven.artifact.Artifact) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Example 45 with MojoExecutionException

use of org.apache.maven.plugin.MojoExecutionException in project asterixdb by apache.

the class LexerGeneratorMojo method execute.

public void execute() throws MojoExecutionException {
    LexerGenerator lexer = new LexerGenerator(getLog());
    HashMap<String, String> config = new HashMap<String, String>();
    getLog().info("--- Lexer Generator Maven Plugin - started with grammarFile: " + grammarFile.toString());
    try {
        String input = readFile(grammarFile);
        config.put("OUTPUT_DIR", outputDir.toString());
        boolean tokens = false;
        for (String line : input.split("\r?\n")) {
            line = line.trim();
            if (line.length() == 0 || line.charAt(0) == '#')
                continue;
            if (tokens == false && !line.equals("TOKENS:")) {
                config.put(line.split("\\s*:\\s*")[0], line.split("\\s*:\\s*")[1]);
            } else if (line.equals("TOKENS:")) {
                tokens = true;
            } else {
                lexer.addToken(line);
            }
        }
        lexer.generateLexer(config);
    } catch (Throwable e) {
        throw new MojoExecutionException("Error while generating lexer", e);
    }
    String parsedGrammar = lexer.printParsedGrammar();
    getLog().info("--- Generated grammar:\n" + parsedGrammar);
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) LexerGenerator(org.apache.asterix.lexergenerator.LexerGenerator)

Aggregations

MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1221 IOException (java.io.IOException)656 File (java.io.File)572 MojoFailureException (org.apache.maven.plugin.MojoFailureException)275 Artifact (org.apache.maven.artifact.Artifact)162 ArrayList (java.util.ArrayList)151 FileInputStream (java.io.FileInputStream)77 MavenProject (org.apache.maven.project.MavenProject)76 HashMap (java.util.HashMap)68 Properties (java.util.Properties)63 FileOutputStream (java.io.FileOutputStream)61 Map (java.util.Map)60 URL (java.net.URL)59 MalformedURLException (java.net.MalformedURLException)57 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)52 FileWriter (java.io.FileWriter)50 List (java.util.List)49 URLClassLoader (java.net.URLClassLoader)45 LinkedHashSet (java.util.LinkedHashSet)40 InputStream (java.io.InputStream)38