Search in sources :

Example 31 with ComponentLookupException

use of org.codehaus.plexus.component.repository.exception.ComponentLookupException in project drools by kiegroup.

the class MavenEmbedder method buildProjects.

public List<ProjectBuildingResult> buildProjects(File mavenProject, boolean recursive) throws ProjectBuildingException, MavenEmbedderException {
    ClassLoader originalCl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(componentProvider.getSystemClassLoader());
        ProjectBuilder projectBuilder = componentProvider.lookup(ProjectBuilder.class);
        return projectBuilder.build(Collections.singletonList(mavenProject), recursive, getProjectBuildingRequest());
    } catch (ComponentLookupException e) {
        throw new MavenEmbedderException(e.getMessage(), e);
    } finally {
        Thread.currentThread().setContextClassLoader(originalCl);
    }
}
Also used : ProjectBuilder(org.apache.maven.project.ProjectBuilder) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException)

Example 32 with ComponentLookupException

use of org.codehaus.plexus.component.repository.exception.ComponentLookupException in project docker-maven-plugin by fabric8io.

the class AuthConfigFactory method decrypt.

private String decrypt(String password) throws MojoExecutionException {
    try {
        // Done by reflection since I have classloader issues otherwise
        Object secDispatcher = container.lookup(SecDispatcher.ROLE, "maven");
        Method method = secDispatcher.getClass().getMethod("decrypt", String.class);
        return (String) method.invoke(secDispatcher, password);
    } catch (ComponentLookupException e) {
        throw new MojoExecutionException("Error looking security dispatcher", e);
    } catch (ReflectiveOperationException e) {
        throw new MojoExecutionException("Cannot decrypt password: " + e.getCause(), e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JsonObject(com.google.gson.JsonObject) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) Method(java.lang.reflect.Method)

Example 33 with ComponentLookupException

use of org.codehaus.plexus.component.repository.exception.ComponentLookupException in project tycho by eclipse.

the class DefaultEquinoxInstallationFactory method unpack.

protected void unpack(File source, File destination) {
    UnArchiver unzip;
    try {
        unzip = plexus.lookup(UnArchiver.class, "zip");
    } catch (ComponentLookupException e) {
        throw new RuntimeException("Could not lookup required component", e);
    }
    unzip.setIgnorePermissions(true);
    destination.mkdirs();
    unzip.setSourceFile(source);
    unzip.setDestDirectory(destination);
    try {
        unzip.extract();
    } catch (ArchiverException e) {
        throw new RuntimeException("Unable to unpack jar " + source, e);
    }
}
Also used : ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) UnArchiver(org.codehaus.plexus.archiver.UnArchiver)

Example 34 with ComponentLookupException

use of org.codehaus.plexus.component.repository.exception.ComponentLookupException in project tycho by eclipse.

the class DefaultDependencyResolverFactory method lookupDependencyResolver.

public DependencyResolver lookupDependencyResolver(MavenProject project) {
    Properties properties = (Properties) project.getContextValue(TychoConstants.CTX_MERGED_PROPERTIES);
    TargetPlatformConfiguration configuration = TychoProjectUtils.getTargetPlatformConfiguration(project);
    String property = properties.getProperty("tycho.targetPlatform");
    DependencyResolver resolver;
    if (property != null) {
        logger.warn("-Dtycho.targetPlatform is deprecated and WILL be removed in the next Tycho version.");
        File location = new File(property);
        if (!location.exists() || !location.isDirectory()) {
            throw new RuntimeException("Invalid target platform location: " + property);
        }
        try {
            resolver = container.lookup(DependencyResolver.class, LocalDependencyResolver.ROLE_HINT);
        } catch (ComponentLookupException e) {
            throw new RuntimeException("Could not instantiate required component", e);
        }
        try {
            ((LocalDependencyResolver) resolver).setLocation(new File(property));
        } catch (IOException e) {
            throw new RuntimeException("Could not create target platform", e);
        }
        return resolver;
    }
    String resolverRole = configuration.getTargetPlatformResolver();
    if (resolverRole == null) {
        resolverRole = DEFAULT_RESOLVER_HINT;
    }
    try {
        resolver = container.lookup(DependencyResolver.class, resolverRole);
    } catch (ComponentLookupException e) {
        throw new RuntimeException("Could not instantiate required component", e);
    }
    return resolver;
}
Also used : LocalDependencyResolver(org.eclipse.tycho.core.osgitools.targetplatform.LocalDependencyResolver) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) IOException(java.io.IOException) Properties(java.util.Properties) TargetPlatformConfiguration(org.eclipse.tycho.core.TargetPlatformConfiguration) File(java.io.File) DependencyResolver(org.eclipse.tycho.core.DependencyResolver) LocalDependencyResolver(org.eclipse.tycho.core.osgitools.targetplatform.LocalDependencyResolver)

Example 35 with ComponentLookupException

use of org.codehaus.plexus.component.repository.exception.ComponentLookupException in project plugin-compat-tester by jenkinsci.

the class PluginCompatTester method testPluginAgainst.

private TestExecutionResult testPluginAgainst(MavenCoordinates coreCoordinates, Plugin plugin, MavenRunner.Config mconfig, PomData pomData, Map<String, Plugin> otherPlugins, Map<String, String> pluginGroupIds, PluginCompatTesterHooks pcth) throws PluginSourcesUnavailableException, PomTransformationException, PomExecutionException, IOException {
    System.out.println(String.format("%n%n%n%n%n"));
    System.out.println(String.format("#############################################"));
    System.out.println(String.format("#############################################"));
    System.out.println(String.format("##%n## Starting to test plugin %s v%s%n## against %s%n##", plugin.name, plugin.version, coreCoordinates));
    System.out.println(String.format("#############################################"));
    System.out.println(String.format("#############################################"));
    System.out.println(String.format("%n%n%n%n%n"));
    File pluginCheckoutDir = new File(config.workDirectory.getAbsolutePath() + File.separator + plugin.name + File.separator);
    try {
        // Run any precheckout hooks
        Map<String, Object> beforeCheckout = new HashMap<String, Object>();
        beforeCheckout.put("pluginName", plugin.name);
        beforeCheckout.put("plugin", plugin);
        beforeCheckout.put("pomData", pomData);
        beforeCheckout.put("config", config);
        beforeCheckout.put("runCheckout", true);
        beforeCheckout = pcth.runBeforeCheckout(beforeCheckout);
        if (beforeCheckout.get("executionResult") != null) {
            // Check if the hook returned a result
            return (TestExecutionResult) beforeCheckout.get("executionResult");
        } else if ((boolean) beforeCheckout.get("runCheckout")) {
            if (beforeCheckout.get("checkoutDir") != null) {
                pluginCheckoutDir = (File) beforeCheckout.get("checkoutDir");
            }
            if (pluginCheckoutDir.exists()) {
                System.out.println("Deleting working directory " + pluginCheckoutDir.getAbsolutePath());
                FileUtils.deleteDirectory(pluginCheckoutDir);
            }
            pluginCheckoutDir.mkdir();
            System.out.println("Created plugin checkout dir : " + pluginCheckoutDir.getAbsolutePath());
            if (localCheckoutProvided()) {
                if (!onlyOnePluginIncluded()) {
                    File localCheckoutPluginDir = new File(config.getLocalCheckoutDir(), plugin.name);
                    File pomLocalCheckoutPluginDir = new File(localCheckoutPluginDir, "pom.xml");
                    if (pomLocalCheckoutPluginDir.exists()) {
                        System.out.println("Copy plugin directory from : " + localCheckoutPluginDir.getAbsolutePath());
                        FileUtils.copyDirectoryStructure(localCheckoutPluginDir, pluginCheckoutDir);
                    } else {
                        cloneFromSCM(pomData.getConnectionUrl(), plugin.name, plugin.version, pluginCheckoutDir);
                    }
                } else {
                    // TODO this fails when it encounters symlinks (e.g. work/jobs/…/builds/lastUnstableBuild),
                    // and even up-to-date versions of org.apache.commons.io.FileUtils seem to not handle links,
                    // so may need to use something like http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/essential/io/examples/Copy.java
                    System.out.println("Copy plugin directory from : " + config.getLocalCheckoutDir().getAbsolutePath());
                    FileUtils.copyDirectoryStructure(config.getLocalCheckoutDir(), pluginCheckoutDir);
                }
            } else {
                // These hooks could redirect the SCM, skip checkout (if multiple plugins use the same preloaded repo)
                cloneFromSCM(pomData.getConnectionUrl(), plugin.name, plugin.version, pluginCheckoutDir);
            }
        } else {
            // If the plugin exists in a different directory (multimodule plugins)
            if (beforeCheckout.get("pluginDir") != null) {
                pluginCheckoutDir = (File) beforeCheckout.get("checkoutDir");
            }
            System.out.println("The plugin has already been checked out, likely due to a multimodule situation. Continue.");
        }
    } catch (ComponentLookupException e) {
        System.err.println("Error : " + e.getMessage());
        throw new PluginSourcesUnavailableException("Problem while creating ScmManager !", e);
    } catch (Exception e) {
        System.err.println("Error : " + e.getMessage());
        throw new PluginSourcesUnavailableException("Problem while checking out plugin sources!", e);
    }
    File buildLogFile = createBuildLogFile(config.reportFile, plugin.name, plugin.version, coreCoordinates);
    // Creating log directory
    FileUtils.forceMkdir(buildLogFile.getParentFile());
    // Creating log file
    FileUtils.fileWrite(buildLogFile.getAbsolutePath(), "");
    // Ran the BeforeCompileHooks
    Map<String, Object> beforeCompile = new HashMap<String, Object>();
    beforeCompile.put("pluginName", plugin.name);
    beforeCompile.put("plugin", plugin);
    beforeCompile.put("pluginDir", pluginCheckoutDir);
    beforeCompile.put("pomData", pomData);
    beforeCompile.put("config", config);
    beforeCompile.put("core", coreCoordinates);
    Map<String, Object> hookInfo = pcth.runBeforeCompilation(beforeCompile);
    boolean ranCompile = hookInfo.containsKey(PluginCompatTesterHookBeforeCompile.OVERRIDE_DEFAULT_COMPILE) ? (boolean) hookInfo.get(PluginCompatTesterHookBeforeCompile.OVERRIDE_DEFAULT_COMPILE) : false;
    try {
        // We also skip potential javadoc execution to avoid general test failure.
        if (!ranCompile) {
            runner.run(mconfig, pluginCheckoutDir, buildLogFile, "clean", "process-test-classes", "-Dmaven.javadoc.skip");
        }
        ranCompile = true;
        // Then transform the POM and run tests against that.
        // You might think that it would suffice to run e.g.
        // -Dmaven-surefire-plugin.version=2.15 -Dmaven.test.dependency.excludes=org.jenkins-ci.main:jenkins-war -Dmaven.test.additionalClasspath=/…/org/jenkins-ci/main/jenkins-war/1.580.1/jenkins-war-1.580.1.war clean test
        // (2.15+ required for ${maven.test.dependency.excludes} and ${maven.test.additionalClasspath} to be honored from CLI)
        // but it does not work; there are lots of linkage errors as some things are expected to be in the test classpath which are not.
        // Much simpler to do use the parent POM to set up the test classpath.
        MavenPom pom = new MavenPom(pluginCheckoutDir);
        try {
            addSplitPluginDependencies(plugin.name, mconfig, pluginCheckoutDir, pom, otherPlugins, pluginGroupIds, coreCoordinates.version);
        } catch (Exception x) {
            x.printStackTrace();
            pomData.getWarningMessages().add(Functions.printThrowable(x));
        // but continue
        }
        List<String> args = new ArrayList<String>();
        args.add("--define=maven.test.redirectTestOutputToFile=false");
        args.add("--define=concurrency=1");
        args.add("hpi:resolve-test-dependencies");
        args.add("hpi:test-hpl");
        args.add("surefire:test");
        // Run preexecution hooks
        Map<String, Object> forExecutionHooks = new HashMap<String, Object>();
        forExecutionHooks.put("pluginName", plugin.name);
        forExecutionHooks.put("args", args);
        forExecutionHooks.put("pomData", pomData);
        forExecutionHooks.put("pom", pom);
        forExecutionHooks.put("coreCoordinates", coreCoordinates);
        forExecutionHooks.put("config", config);
        forExecutionHooks.put("pluginDir", pluginCheckoutDir);
        pcth.runBeforeExecution(forExecutionHooks);
        runner.run(mconfig, pluginCheckoutDir, buildLogFile, ((List<String>) forExecutionHooks.get("args")).toArray(new String[args.size()]));
        return new TestExecutionResult(((PomData) forExecutionHooks.get("pomData")).getWarningMessages());
    } catch (PomExecutionException e) {
        PomExecutionException e2 = new PomExecutionException(e);
        e2.getPomWarningMessages().addAll(pomData.getWarningMessages());
        if (ranCompile) {
            // So the status is considered to be TEST_FAILURES not COMPILATION_ERROR:
            e2.succeededPluginArtifactIds.add("maven-compiler-plugin");
        }
        throw e2;
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) PomExecutionException(org.jenkins.tools.test.exception.PomExecutionException) PlexusContainerException(org.codehaus.plexus.PlexusContainerException) PluginSourcesUnavailableException(org.jenkins.tools.test.exception.PluginSourcesUnavailableException) FileNotFoundException(java.io.FileNotFoundException) ScmException(org.apache.maven.scm.ScmException) TransformerException(javax.xml.transform.TransformerException) PomExecutionException(org.jenkins.tools.test.exception.PomExecutionException) PomTransformationException(org.jenkins.tools.test.exception.PomTransformationException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) MavenEmbedderException(hudson.maven.MavenEmbedderException) IOException(java.io.IOException) MavenPom(org.jenkins.tools.test.model.MavenPom) JSONObject(net.sf.json.JSONObject) PluginSourcesUnavailableException(org.jenkins.tools.test.exception.PluginSourcesUnavailableException) JarFile(java.util.jar.JarFile) File(java.io.File) TestExecutionResult(org.jenkins.tools.test.model.TestExecutionResult)

Aggregations

ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)40 IOException (java.io.IOException)11 ServerException (com.ctrip.xpipe.redis.console.exception.ServerException)7 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 ArrayList (java.util.ArrayList)6 PostConstruct (javax.annotation.PostConstruct)6 File (java.io.File)5 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)5 Artifact (org.apache.maven.artifact.Artifact)4 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)4 MavenSession (org.apache.maven.execution.MavenSession)4 SettingsBuildingException (org.apache.maven.settings.building.SettingsBuildingException)4 LinkedHashMap (java.util.LinkedHashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 InvalidRepositoryException (org.apache.maven.artifact.InvalidRepositoryException)3 ArtifactMetadataRetrievalException (org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException)3 ArtifactMetadataSource (org.apache.maven.artifact.metadata.ArtifactMetadataSource)3 ResolutionGroup (org.apache.maven.artifact.metadata.ResolutionGroup)3 DefaultMetadataResolutionRequest (org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest)3 MetadataResolutionRequest (org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest)3