Search in sources :

Example 36 with MojoFailureException

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

the class Dependency31Helper method resolveById.

@Override
public File resolveById(String id, Log log) throws MojoFailureException {
    if (id.startsWith("mvn:")) {
        if (id.contains("!")) {
            id = id.substring(0, "mvn:".length()) + id.substring(id.indexOf("!") + 1);
        }
        if (id.endsWith("/")) {
            id = id.substring(0, id.length() - 1);
        }
    }
    id = MavenUtil.mvnToAether(id);
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(new DefaultArtifact(id));
    request.setRepositories(projectRepositories);
    log.debug("Resolving artifact " + id + " from " + projectRepositories);
    ArtifactResult result;
    try {
        result = repositorySystem.resolveArtifact(repositorySystemSession, request);
    } catch (ArtifactResolutionException e) {
        log.warn("Could not resolve " + id, e);
        throw new MojoFailureException(format("Couldn't resolve artifact %s", id), e);
    }
    log.debug("Resolved artifact " + id + " to " + result.getArtifact().getFile() + " from " + result.getRepository());
    return result.getArtifact().getFile();
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 37 with MojoFailureException

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

the class GenerateHelpMojo method createFinder.

private ClassFinder createFinder(String classloaderType) throws Exception {
    ClassFinder finder;
    if ("project".equals(classloaderType)) {
        List<URL> urls = new ArrayList<>();
        for (Object object : project.getCompileClasspathElements()) {
            String path = (String) object;
            urls.add(new File(path).toURI().toURL());
        }
        ClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader());
        finder = new ClassFinder(loader, urls);
    } else if ("plugin".equals(classLoader)) {
        finder = new ClassFinder(getClass().getClassLoader());
    } else {
        throw new MojoFailureException("classLoader attribute must be 'project' or 'plugin'");
    }
    return finder;
}
Also used : URLClassLoader(java.net.URLClassLoader) ClassFinder(org.apache.xbean.finder.ClassFinder) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) URLClassLoader(java.net.URLClassLoader) File(java.io.File) URL(java.net.URL)

Example 38 with MojoFailureException

use of org.apache.maven.plugin.MojoFailureException 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 39 with MojoFailureException

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

the class ArchiveMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    getLog().debug("Setting artifact file: " + targetFile);
    org.apache.maven.artifact.Artifact artifact = project.getArtifact();
    artifact.setFile(targetFile);
    try {
        //now pack up the server.
        if (archiveTarGz) {
            archive("tar.gz");
        }
        if (archiveZip) {
            archive("zip");
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Could not archive plugin", e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Artifact(org.apache.maven.artifact.Artifact) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 40 with MojoFailureException

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

the class RunMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    if (karafDirectory.exists()) {
        getLog().info("Using Karaf container located " + karafDirectory.getAbsolutePath());
    } else {
        getLog().info("Extracting Karaf container");
        try {
            File karafArchiveFile = resolveFile(karafDistribution);
            extract(karafArchiveFile, karafDirectory);
        } catch (Exception e) {
            throw new MojoFailureException("Can't extract Karaf container", e);
        }
    }
    getLog().info("Starting Karaf container");
    System.setProperty("karaf.home", karafDirectory.getAbsolutePath());
    System.setProperty("karaf.base", karafDirectory.getAbsolutePath());
    System.setProperty("karaf.data", karafDirectory.getAbsolutePath() + "/data");
    System.setProperty("karaf.etc", karafDirectory.getAbsolutePath() + "/etc");
    System.setProperty("karaf.instances", karafDirectory.getAbsolutePath() + "/instances");
    System.setProperty("karaf.startLocalConsole", "false");
    System.setProperty("karaf.startRemoteShell", startSsh);
    System.setProperty("karaf.lock", "false");
    Main main = new Main(new String[0]);
    try {
        main.launch();
        while (main.getFramework().getState() != Bundle.ACTIVE) {
            Thread.sleep(1000);
        }
        BundleContext bundleContext = main.getFramework().getBundleContext();
        Object bootFinished = null;
        while (bootFinished == null) {
            Thread.sleep(1000);
            ServiceReference ref = bundleContext.getServiceReference(BootFinished.class);
            if (ref != null) {
                bootFinished = bundleContext.getService(ref);
            }
        }
        deploy(bundleContext);
        if (keepRunning)
            main.awaitShutdown();
        main.destroy();
    } catch (Throwable e) {
        throw new MojoExecutionException("Can't start container", e);
    } finally {
        System.gc();
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Main(org.apache.karaf.main.Main) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

MojoFailureException (org.apache.maven.plugin.MojoFailureException)157 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)94 File (java.io.File)93 IOException (java.io.IOException)91 ArrayList (java.util.ArrayList)50 TreeSet (java.util.TreeSet)33 FileInputStream (java.io.FileInputStream)32 FileOutputStream (java.io.FileOutputStream)21 List (java.util.List)21 Map (java.util.Map)21 MavenProject (org.apache.maven.project.MavenProject)18 Set (java.util.Set)15 MalformedURLException (java.net.MalformedURLException)14 HashMap (java.util.HashMap)13 HashSet (java.util.HashSet)13 InputStream (java.io.InputStream)12 URLClassLoader (java.net.URLClassLoader)12 Matcher (java.util.regex.Matcher)12 Artifact (org.apache.maven.artifact.Artifact)12 AbstractMojo (org.apache.maven.plugin.AbstractMojo)12